/// <summary> /// Add service to the service manager container /// </summary> /// <typeparam name="T">Service type</typeparam> /// <param name="service">Service instance</param> /// <param name="type"> /// Optional type to register the instance for. In Visual Studio /// some global services are registered as 'SVsService` while /// actual interface type is IVsService. /// </param> public virtual IServiceManager AddService <T>(T service, Type type = null) where T : class { _disposeToken.ThrowIfDisposed(); type = type ?? typeof(T); Check.ArgumentNull(nameof(service), service); Check.InvalidOperation(() => _s.TryAdd(type, service), "Service already exists"); ServiceAdded?.Invoke(this, new ServiceContainerEventArgs(type)); return(this); }
/// <summary> /// Add service to the service manager container /// </summary> /// <typeparam name="T">Service type</typeparam> /// <param name="service">Service instance</param> public virtual IServiceManager AddService <T>(T service) where T : class { _disposeToken.ThrowIfDisposed(); var type = typeof(T); Check.ArgumentNull(nameof(service), service); Check.Operation(() => _s.TryAdd(type, service)); ServiceAdded?.Invoke(this, new ServiceContainerEventArgs(type)); return(this); }
/// <summary> /// Adds on-demand created service /// </summary> /// <param name="type">Service type</param> /// <param name="factory">Optional creator function. If not provided, reflection with default constructor will be used.</param> /// <param name="parameters">Factory parameters</param> public virtual IServiceManager AddService(Type type, Func <object> factory) { Check.ArgumentNull(nameof(type), type); lock (_lock) { Check.InvalidOperation(() => _services.ContainsKey(type)); Check.InvalidOperation(() => _deferredServices.ContainsKey(type)); _deferredServices[type] = factory; } ServiceAdded?.Invoke(this, new ServiceContainerEventArgs(type)); return(this); }
/// <summary> /// Add service to the service manager container /// </summary> /// <typeparam name="T">Service type</typeparam> /// <param name="service">Service instance</param> public virtual IServiceManager AddService <T>(T service) where T : class { var type = typeof(T); Check.ArgumentNull(nameof(service), service); lock (_lock) { Check.InvalidOperation(() => _services.ContainsKey(type)); _services[type] = service; } ServiceAdded?.Invoke(this, new ServiceContainerEventArgs(type)); return(this); }
/// <summary> /// Adds on-demand created service /// </summary> /// <param name="factory">Optional creator function. If not provided, reflection with default constructor will be used.</param> public virtual IServiceManager AddService <T>(Func <T> factory) where T : class { _disposeToken.ThrowIfDisposed(); var type = typeof(T); var lazy = factory != null ? new Lazy <object>(() => factory()) : new Lazy <object>(() => Activator.CreateInstance(type)); Check.InvalidOperation(() => _s.TryAdd(type, lazy), "Service already exists"); ServiceAdded?.Invoke(this, new ServiceContainerEventArgs(typeof(T))); return(this); }
protected void AddService <T>(T serviceInstance) where T : class { var added = false; lock (_lock) { if (GetService <T>(false) == null) { _servicesByType.Add(typeof(T), serviceInstance); added = true; } } if (added) { ServiceAdded?.Invoke(this, new ServiceManagerEventArgs(typeof(T), serviceInstance)); } }
private void OnServiceAdded(ServiceEventArgs e) { ServiceAdded?.Invoke(this, e); }
internal void OnServiceAdded(EntityApp app, Type serviceType, object serviceInstance) { ServiceAdded?.Invoke(this, new ServiceEventArgs(app, serviceType, serviceInstance)); }
public void AddService(object service) { ImmutableInterlocked.Update(ref services, p => p.Add(service)); ServiceAdded?.Invoke(this, service); }
/// <summary> /// Add a HEROsModService to the ServiceController /// </summary> /// <param name="service">Service to add</param> public void AddService(HEROsModService service) { _services.Add(service); ServiceAdded?.Invoke(service); }