/// <summary> /// Register your service by type value to the Service Locator dictionary. /// It will trigger an event that service was added. This event subscribers for callback. /// You can't register the same service twice. /// </summary> /// <param name="service"></param> /// <typeparam name="T"></typeparam> /// <exception cref="ArgumentException"></exception> public static void Register <T>(T service) { var serviceType = typeof(T); if (!services.ContainsKey(serviceType)) { services.Add(serviceType, service); OnServiceAdded?.Invoke(serviceType); } else { throw new ArgumentException($"<color=red><b>The service {serviceType.Name} has already been added</b></color>"); } }
public Result AddService(ServiceModel service) { if (string.IsNullOrEmpty(service.Name)) { return(Result.Fail($"The property 'Name' is required.")); } if (string.IsNullOrEmpty(service.DisplayName)) { return(Result.Fail($"The property 'DisplayName' is required.")); } if (string.IsNullOrEmpty(service.Filename)) { return(Result.Fail($"The property 'Filename' is required.")); } var tabPages = tabControl.TabPages.Cast <TabPage>(); if (tabPages.Any(x => x.Name == service.Name)) { return(Result.Fail($"There is already a service registered with the name '{service.Name}'")); } var serviceExecutionModel = new ServiceExecutionModel(service); var tab = CreateTab( service.Name, service.DisplayName, serviceExecutionModel.Logger, serviceExecutionModel ); ModifyUI(() => { tabControl.TabPages.Add(tab); }); serviceExecutionModel.Start(); try { OnServiceAdded?.Invoke(this, new EventArgs <ServiceModel>(service)); } catch (Exception ex) { mainLogger.Error(ex.ToString()); } return(Result.Successful()); }
public void AddService(IGattServerService service) { (service as GattServerService).AddToServer(this); OnServiceAdded?.Invoke(this, service); }