Skip to content
Documentation

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.IDisposable

Implements IActivatedContainer, System.IDisposable

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();

IActivatedContainer
The activated IContainer as an IActivatedContainer

Determines whether a service of the specified serviceType has been registered.

bool HasService(System.Type serviceType);

serviceType System.Type

The service type to check for.

System.Boolean
true if the service is registered; otherwise, false.

Determines whether a service of type TService has been registered.

bool HasService<TService>();

TService

The service type to check for.

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;

TService

The service to resolve.

service TService

The service or null if none could be resolved.

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;

TService

The type of the services to resolve.

services System.Collections.Generic.IEnumerable<TService>

The services or null if none could be resolved.

System.Boolean
true if the services were resolved; otherwise, false.

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);

service System.Type

The service type/interface to register.

implementation System.Type

The implementation type to be injected for service.

IContainer
The IContainer itself.

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);

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.

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;

TService

The registering type/interface.

TImplementation

The type to be injected.

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;

TService

The registering type/interface.

TImplementation

The type to be injected.

skipIfServiceTypeAlreadyRegistered System.Boolean

When true, skips registration if TService is already registered.

IContainer
The IContainer itself.

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;

TService

The registering type/interface.

implementation System.Type

The type to be injected.

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;

TService

The registering type/interface.

implementation System.Type

The type to be injected.

skipIfServiceTypeAlreadyRegistered System.Boolean

When true, skips registration if TService is already registered.

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;

TService

The registering type/interface.

instance TService

The instance implementing TService.

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;

TService

The registering type/interface.

instance TService

The instance implementing TService.

skipIfServiceTypeAlreadyRegistered System.Boolean

When true, skips registration if TService is already registered.

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;

TService

The type/interface for which TImplementation is being registered.

TImplementation

The type to be registered for TService.

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;

TService

The type/interface for which TImplementation is being registered.

TImplementation

The type to be registered for TService.

skipIfServiceTypeAlreadyRegistered System.Boolean

When true, skips registration if TService is already registered.

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;

TService

factory System.Func<IActivatedContainer,TService>

IContainer

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;

TService

factory System.Func<IActivatedContainer,TService>

skipIfServiceTypeAlreadyRegistered System.Boolean

IContainer

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;

TService

The registering type/interface.

instance TService

The instance implementing TService.

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;

TService

The registering type/interface.

instance TService

The instance implementing TService.

skipIfServiceTypeAlreadyRegistered System.Boolean

When true, skips registration if TService is already registered.

IContainer
The IContainer itself.

© 2026 Volue.Version v0.6.38017 November 2026