IContainer Interface
Dependency injection container used to register and resolve services and their implementing types.
public interface IContainer : HAKOM.DependencyInjection.Core.Net.Api.IActivatedContainer, System.IDisposableImplements IActivatedContainer, System.IDisposable
Methods
Section titled “Methods”IContainer.Activate() Method
Section titled “IContainer.Activate() Method”Seals the container against additional registrations. May perform additional tasks such as checking against circular dependencies, etc. Must be called <i>before</i> any call to Resolve<TService>().
HAKOM.DependencyInjection.Core.Net.Api.IActivatedContainer Activate();Returns
Section titled “Returns”IActivatedContainer
The activated IContainer as an IActivatedContainer
IContainer.HasService(Type) Method
Section titled “IContainer.HasService(Type) Method”Determines whether a service of the specified serviceType has been registered.
bool HasService(System.Type serviceType);Parameters
Section titled “Parameters”serviceType System.Type
The service type to check for.
Returns
Section titled “Returns”System.Boolean
true if the service is registered; otherwise, false.
IContainer.HasService<TService>() Method
Section titled “IContainer.HasService<TService>() Method”Determines whether a service of type TService has been registered.
bool HasService<TService>();Type parameters
Section titled “Type parameters”TService
The service type to check for.
Returns
Section titled “Returns”System.Boolean
true if the service is registered; otherwise, false.
IContainer.TryResolveSingletonEarly<TService>(TService) Method
Section titled “IContainer.TryResolveSingletonEarly<TService>(TService) Method”Resolves an already registered singleton service before the container has been activated. There are only very few use cases for this. Use with caution.
bool TryResolveSingletonEarly<TService>(out TService? service) where TService : class;Type parameters
Section titled “Type parameters”TService
The service to resolve.
Parameters
Section titled “Parameters”service TService
The service or null if none could be resolved.
Returns
Section titled “Returns”System.Boolean
true if the service was resolved; otherwise, false.
IContainer.TryResolveSingletonsEarly<TService>(IEnumerable<TService>) Method
Section titled “IContainer.TryResolveSingletonsEarly<TService>(IEnumerable<TService>) Method”Resolves already registered singleton services of the same type before the container has been activated. There are only very few use cases for this. Use with caution.
bool TryResolveSingletonsEarly<TService>(out System.Collections.Generic.IEnumerable<TService>? services) where TService : class;Type parameters
Section titled “Type parameters”TService
The type of the services to resolve.
Parameters
Section titled “Parameters”services System.Collections.Generic.IEnumerable<TService>
The services or null if none could be resolved.
Returns
Section titled “Returns”System.Boolean
true if the services were resolved; otherwise, false.
IContainer.Use(Type, Type) Method
Section titled “IContainer.Use(Type, Type) Method”Registers the given implementation type implementation to be injected into any class requesting an instance of service in its constructor. The implementation is instantiated every time it is requested.
To reduce potential occurrences of runtime exceptions, consider using Use<TService,TImplementation>() instead as this uses type constraints to produce compile-time errors in case implementation does not implement service.
This may be useful when registering unbound generics, for example: registering Class<T> to be used whenever an IInterface<T> is requested:
container.Use(typeof(IInterface<>), typeof(Class<>));HAKOM.DependencyInjection.Core.Net.Api.IContainer Use(System.Type service, System.Type implementation);Parameters
Section titled “Parameters”service System.Type
The service type/interface to register.
implementation System.Type
The implementation type to be injected for service.
Returns
Section titled “Returns”IContainer
The IContainer itself.
IContainer.Use(Type, Type, bool) Method
Section titled “IContainer.Use(Type, Type, bool) Method”Registers the given implementation type implementation to be injected into any class requesting an instance of service in its constructor. The implementation is instantiated every time it is requested. If skipIfServiceTypeAlreadyRegistered is true and service is already registered, the call is silently ignored.
HAKOM.DependencyInjection.Core.Net.Api.IContainer Use(System.Type service, System.Type implementation, bool skipIfServiceTypeAlreadyRegistered);Parameters
Section titled “Parameters”service System.Type
The registering type/interface.
implementation System.Type
The type to be injected.
skipIfServiceTypeAlreadyRegistered System.Boolean
When true, skips registration if service is already registered.
Returns
Section titled “Returns”IContainer
The IContainer itself.
IContainer.Use<TService,TImplementation>() Method
Section titled “IContainer.Use<TService,TImplementation>() Method”Registers the given implementation type to be injected into any class depending on it. The type is instantiated every time it is requested.
HAKOM.DependencyInjection.Core.Net.Api.IContainer Use<TService,TImplementation>() where TService : class where TImplementation : class, TService;Type parameters
Section titled “Type parameters”TService
The registering type/interface.
TImplementation
The type to be injected.
Returns
Section titled “Returns”IContainer
The IContainer itself.
IContainer.Use<TService,TImplementation>(bool) Method
Section titled “IContainer.Use<TService,TImplementation>(bool) Method”Registers the given implementation type to be injected into any class depending on it. The type is instantiated every time it is requested. If skipIfServiceTypeAlreadyRegistered is true and TService is already registered, the call is silently ignored.
HAKOM.DependencyInjection.Core.Net.Api.IContainer Use<TService,TImplementation>(bool skipIfServiceTypeAlreadyRegistered) where TService : class where TImplementation : class, TService;Type parameters
Section titled “Type parameters”TService
The registering type/interface.
TImplementation
The type to be injected.
Parameters
Section titled “Parameters”skipIfServiceTypeAlreadyRegistered System.Boolean
When true, skips registration if TService is already registered.
Returns
Section titled “Returns”IContainer
The IContainer itself.
IContainer.Use<TService>(Type) Method
Section titled “IContainer.Use<TService>(Type) Method”Registers the given implementation type implementation to be injected into any class requesting an instance of TService in its constructor. The implementation is instantiated every time it is requested. To reduce potential occurrences of runtime exceptions, consider using Use<TService,TImplementation>() instead as this uses type constraints to produce compile-time errors in case implementation does not implement TService.
HAKOM.DependencyInjection.Core.Net.Api.IContainer Use<TService>(System.Type implementation) where TService : class;Type parameters
Section titled “Type parameters”TService
The registering type/interface.
Parameters
Section titled “Parameters”implementation System.Type
The type to be injected.
Returns
Section titled “Returns”IContainer
The IContainer itself.
IContainer.Use<TService>(Type, bool) Method
Section titled “IContainer.Use<TService>(Type, bool) Method”Registers the given implementation type implementation to be injected into any class requesting an instance of TService in its constructor. The implementation is instantiated every time it is requested. If skipIfServiceTypeAlreadyRegistered is true and TService is already registered, the call is silently ignored.
HAKOM.DependencyInjection.Core.Net.Api.IContainer Use<TService>(System.Type implementation, bool skipIfServiceTypeAlreadyRegistered) where TService : class;Type parameters
Section titled “Type parameters”TService
The registering type/interface.
Parameters
Section titled “Parameters”implementation System.Type
The type to be injected.
skipIfServiceTypeAlreadyRegistered System.Boolean
When true, skips registration if TService is already registered.
Returns
Section titled “Returns”IContainer
The IContainer itself.
IContainer.UseAndDisposeSingleton<TService>(TService) Method
Section titled “IContainer.UseAndDisposeSingleton<TService>(TService) Method”Registers the given instance to be injected into any class depending on it and makes sure the instance is disposed of along with the container.
HAKOM.DependencyInjection.Core.Net.Api.IContainer UseAndDisposeSingleton<TService>(TService instance) where TService : class, System.IDisposable;Type parameters
Section titled “Type parameters”TService
The registering type/interface.
Parameters
Section titled “Parameters”instance TService
The instance implementing TService.
Returns
Section titled “Returns”IContainer
The IContainer itself.
IContainer.UseAndDisposeSingleton<TService>(TService, bool) Method
Section titled “IContainer.UseAndDisposeSingleton<TService>(TService, bool) Method”Registers the given instance to be injected into any class depending on it and makes sure the instance is disposed of along with the container. If skipIfServiceTypeAlreadyRegistered is true and TService is already registered, the call is silently ignored.
HAKOM.DependencyInjection.Core.Net.Api.IContainer UseAndDisposeSingleton<TService>(TService instance, bool skipIfServiceTypeAlreadyRegistered=false) where TService : class, System.IDisposable;Type parameters
Section titled “Type parameters”TService
The registering type/interface.
Parameters
Section titled “Parameters”instance TService
The instance implementing TService.
skipIfServiceTypeAlreadyRegistered System.Boolean
When true, skips registration if TService is already registered.
Returns
Section titled “Returns”IContainer
The IContainer itself.
IContainer.UseOnce<TService,TImplementation>() Method
Section titled “IContainer.UseOnce<TService,TImplementation>() Method”Registers the given implementation type to be injected into any class depending on it. The type is only instantiated once (having been injected with any dependencies itself) and reused each time it is requested after that.
HAKOM.DependencyInjection.Core.Net.Api.IContainer UseOnce<TService,TImplementation>() where TService : class where TImplementation : class, TService;Type parameters
Section titled “Type parameters”TService
The type/interface for which TImplementation is being registered.
TImplementation
The type to be registered for TService.
Returns
Section titled “Returns”IContainer
The IContainer itself.
IContainer.UseOnce<TService,TImplementation>(bool) Method
Section titled “IContainer.UseOnce<TService,TImplementation>(bool) Method”Registers the given implementation type to be injected into any class depending on it. The type is only instantiated once and reused each time it is requested after that. If skipIfServiceTypeAlreadyRegistered is true and TService is already registered, the call is silently ignored.
HAKOM.DependencyInjection.Core.Net.Api.IContainer UseOnce<TService,TImplementation>(bool skipIfServiceTypeAlreadyRegistered) where TService : class where TImplementation : class, TService;Type parameters
Section titled “Type parameters”TService
The type/interface for which TImplementation is being registered.
TImplementation
The type to be registered for TService.
Parameters
Section titled “Parameters”skipIfServiceTypeAlreadyRegistered System.Boolean
When true, skips registration if TService is already registered.
Returns
Section titled “Returns”IContainer
The IContainer itself.
IContainer.UseOnce<TService>(Func<IActivatedContainer,TService>) Method
Section titled “IContainer.UseOnce<TService>(Func<IActivatedContainer,TService>) Method”Registers a singleton using a factory delegate. Obsolete — do not use.
HAKOM.DependencyInjection.Core.Net.Api.IContainer UseOnce<TService>(System.Func<HAKOM.DependencyInjection.Core.Net.Api.IActivatedContainer,TService> factory) where TService : class;Type parameters
Section titled “Type parameters”TService
Parameters
Section titled “Parameters”factory System.Func<IActivatedContainer,TService>
Returns
Section titled “Returns”IContainer.UseOnce<TService>(Func<IActivatedContainer,TService>, bool) Method
Section titled “IContainer.UseOnce<TService>(Func<IActivatedContainer,TService>, bool) Method”Registers a singleton using a factory delegate, optionally skipping if already registered. Obsolete — do not use.
HAKOM.DependencyInjection.Core.Net.Api.IContainer UseOnce<TService>(System.Func<HAKOM.DependencyInjection.Core.Net.Api.IActivatedContainer,TService> factory, bool skipIfServiceTypeAlreadyRegistered) where TService : class;Type parameters
Section titled “Type parameters”TService
Parameters
Section titled “Parameters”factory System.Func<IActivatedContainer,TService>
skipIfServiceTypeAlreadyRegistered System.Boolean
Returns
Section titled “Returns”IContainer.UseSingleton<TService>(TService) Method
Section titled “IContainer.UseSingleton<TService>(TService) Method”Registers the given instance to be injected into any class depending on it. If TService itself has dependencies to be injected, consider using UseOnce<TService,TImplementation>() instead. If the instance implements System.IDisposable and should be disposed along with the container, consider using UseAndDisposeSingleton<TService>(TService) instead.
HAKOM.DependencyInjection.Core.Net.Api.IContainer UseSingleton<TService>(TService instance) where TService : class;Type parameters
Section titled “Type parameters”TService
The registering type/interface.
Parameters
Section titled “Parameters”instance TService
The instance implementing TService.
Returns
Section titled “Returns”IContainer
The IContainer itself.
IContainer.UseSingleton<TService>(TService, bool) Method
Section titled “IContainer.UseSingleton<TService>(TService, bool) Method”Registers the given instance to be injected into any class depending on it. If skipIfServiceTypeAlreadyRegistered is true and TService is already registered, the call is silently ignored.
HAKOM.DependencyInjection.Core.Net.Api.IContainer UseSingleton<TService>(TService instance, bool skipIfServiceTypeAlreadyRegistered) where TService : class;Type parameters
Section titled “Type parameters”TService
The registering type/interface.
Parameters
Section titled “Parameters”instance TService
The instance implementing TService.
skipIfServiceTypeAlreadyRegistered System.Boolean
When true, skips registration if TService is already registered.
Returns
Section titled “Returns”IContainer
The IContainer itself.