ContainerRegisterInstance Method (Type, Object)

Simple Injector
Registers a single instance that will be returned when an instance of type serviceType is requested. This instance must be thread-safe when working in a multi-threaded environment. NOTE: Do note that instances supplied by this method NEVER get disposed by the container, since the instance is assumed to outlive this container instance. If disposing is required, use RegisterSingleton(Type, Func<object>).

Namespace:  SimpleInjector
Assembly:  SimpleInjector (in SimpleInjector.dll) Version: 4.6.0
Syntax

public void RegisterInstance(
	Type serviceType,
	Object instance
)

Parameters

serviceType
Type: SystemType
The base type or interface to register.
instance
Type: SystemObject
The instance to register.
Exceptions

ExceptionCondition
ArgumentNullExceptionThrown when either serviceType or instance are null references (Nothing in VB).
ArgumentExceptionThrown when instance is no sub type from serviceType.
InvalidOperationException Thrown when this container instance is locked and can not be altered, or when an the serviceType has already been registered.
See Also

Reference