SimpleInjector.AdvancedApiObject
SimpleInjectorContainer
Namespace: SimpleInjector
Assembly: SimpleInjector (in SimpleInjector.dll) Version: 5.3.0
The Container type exposes the following members.
Name | Description | |
---|---|---|
Container | Initializes a new instance of the Container class. |
Name | Description | |
---|---|---|
Collection | Gets the object that allows access to methods related to registration and creation of collections. | |
ContainerScope | Gets the container scope that that manages the lifetime of singletons and other
container-controlled instances. Use this property to register actions that need to be called
and instances that need to be disposed when the container gets disposed. | |
IsLocked |
Gets a value indicating whether the container is locked from making any new registrations. The
container is automatically locked when the first instance is resolved (e.g. by calling
GetInstance).
| |
IsVerifying |
Gets a value indicating whether the container is currently being verified on the current thread.
| |
Options | Gets the container options. |
Name | Description | |
---|---|---|
AddRegistration(Type, Registration) |
Adds the registration for the supplied serviceType. This
method can be used to apply the same Registration to multiple different service
types.
| |
AddRegistrationTService(Registration) |
Adds the registration for the supplied . This
method can be used to apply the same Registration to multiple different service
types.
| |
Dispose | Releases all instances that are cached by the Container object. | |
Dispose(Boolean) | Releases all instances that are cached by the Container object. | |
DisposeContainerAsync |
Releases all instances that are cached by the Container object asynchronously.
| |
Equals | Determines whether the specified object is equal to the current object. (Inherited from ApiObject.) | |
GetAllInstances(Type) |
Gets all instances of the given serviceType currently registered in the container.
| |
GetAllInstancesTService |
Gets all instances of the given TService currently registered in the container.
| |
GetCurrentRegistrations |
Returns an array with the current registrations. This list contains all explicitly registered
types, and all implicitly registered instances. Implicit registrations are all concrete
unregistered types that have been requested, all types that have been resolved using
unregistered type resolution (using the ResolveUnregisteredType event), and
requested unregistered collections. Note that the result of this method may change over time,
because of these implicit registrations.
| |
GetHashCode | Serves as the default hash function. (Inherited from ApiObject.) | |
GetInstance(Type) | Gets an instance of the given serviceType. | |
GetInstanceTService | Gets an instance of the given TService. | |
GetRegistration(Type) |
Gets the InstanceProducer for the given serviceType. When no
registration exists, the container will try creating a new producer. A producer can be created
when the type is a concrete reference type, there is an ResolveUnregisteredType
event registered that acts on that type, or when the service type is an IEnumerableT.
Otherwise null is returned.
| |
GetRegistration(Type, Boolean) |
Gets the InstanceProducer for the given serviceType. When no
registration exists, the container will try creating a new producer. A producer can be created
when the type is a concrete reference type, there is an ResolveUnregisteredType
event registered that acts on that type, or when the service type is an IEnumerableT.
Otherwise null is returned, or an exception is throw when
throwOnFailure is set to true.
| |
GetRegistrationTService |
Gets the InstanceProducer for the given TService. When no
registration exists, the container will try creating a new producer. A producer can be created
when the type is a concrete reference type, there is an ResolveUnregisteredType
event registered that acts on that type, or when the service type is an IEnumerableT.
Otherwise null is returned.
| |
GetRegistrationTService(Boolean) |
Gets the InstanceProducerTService for the given TService.When no
registration exists, the container will try creating a new producer. A producer can be created
when the type is a concrete reference type, there is an ResolveUnregisteredType
event registered that acts on that type, or when the service type is an IEnumerableT.
Otherwise null is returned, or an exception is throw when
throwOnFailure is set to true.
| |
GetRootRegistrations |
Returns an array with the current registrations for root objects. Root objects are registrations
that are in the root of the object graph, meaning that no other registration is depending on it.
| |
GetType | Gets the Type of the current instance. (Inherited from ApiObject.) | |
GetTypesToRegister(Type, IEnumerableAssembly) |
Returns all concrete non-generic types that are located in the supplied assemblies
and implement or inherit from the supplied serviceType.
serviceType can be an open-generic type.
| |
GetTypesToRegister(Type, Assembly) |
Returns all concrete non-generic types that are located in the supplied assemblies
and implement or inherit from the supplied serviceType.
serviceType can be an open-generic type.
| |
GetTypesToRegister(Type, IEnumerableAssembly, TypesToRegisterOptions) |
Returns all concrete types that are located in the supplied assemblies
and implement or inherit from the supplied serviceType and match the specified
options... serviceType can be an open-generic type.
| |
GetTypesToRegisterTService(IEnumerableAssembly) |
Returns all concrete non-generic types that are located in the supplied assemblies
and implement or inherit from the supplied TService.
| |
GetTypesToRegisterTService(Assembly) |
Returns all concrete non-generic types that are located in the supplied assemblies
and implement or inherit from the supplied TService.
| |
GetTypesToRegisterTService(IEnumerableAssembly, TypesToRegisterOptions) |
Returns all concrete types that are located in the supplied assemblies
and implement or inherit from the supplied TService and match the specified
options...
| |
Register(Type) |
Registers that a new instance of concreteType will be returned every time it
is requested (transient).
| |
Register(Type, IEnumerableAssembly) |
Registers all concrete, non-generic, public and internal types in the given set of
assemblies that implement the given openGenericServiceType
with container's default lifestyle (which is transient by default).
Decorators and
generic type definitions
will be excluded from registration, while
composites are included.
| |
Register(Type, IEnumerableType) |
Registers all supplied implementationTypes based on the closed-generic version
of the given openGenericServiceType with the transient lifestyle.
| |
Register(Type, FuncObject) |
Registers the specified delegate that allows returning instances of serviceType.
| |
Register(Type, Assembly) |
Registers all concrete, non-generic, public and internal types in the given set of
assemblies that implement the given openGenericServiceType
with container's default lifestyle (which is transient by default).
Decorators and
generic type definitions
will be excluded from registration, while
composites are included.
| |
Register(Type, Type) |
Registers that a new instance of implementationType will be returned every time a
serviceType is requested. If serviceType and
implementationType represent the same type, the type is registered by itself.
Open and closed generic types are supported.
| |
Register(Type, IEnumerableAssembly, Lifestyle) |
Registers all concrete, non-generic, public and internal types in the given set of
assemblies that implement the given openGenericServiceType
with the supplied lifestyle.
Decorators and
generic type definitions
will be excluded from registration, while
composites are included.
| |
Register(Type, IEnumerableType, Lifestyle) |
Registers all supplied implementationTypes based on the closed-generic version
of the given openGenericServiceType with the given lifestyle.
| |
Register(Type, FuncObject, Lifestyle) |
Registers the specified delegate instanceCreator that will produce instances of
type serviceType and will be returned when an instance of type
serviceType is requested. The delegate is expected to produce new instances on
each call. The instances are cached according to the supplied lifestyle.
| |
Register(Type, Assembly, Lifestyle) |
Registers all concrete, non-generic, public and internal types in the given
assembly that implement the given openGenericServiceType
with the supplied lifestyle.
Decorators and
generic type definitions
will be excluded from registration, while
composites are included.
| |
Register(Type, Type, Lifestyle) |
Registers that an instance of type implementationType will be returned when an
instance of type serviceType is requested. The instance is cached according to
the supplied lifestyle. Open and closed generic types are supported.
| |
RegisterTConcrete |
Registers that a new instance of TConcrete will be returned every time it
is requested (transient).
| |
RegisterTService(FuncTService) |
Registers the specified delegate that allows returning transient instances of
TService. The delegate is expected to always return a new instance on
each call.
| |
RegisterTConcrete(Lifestyle) |
Registers that an instance of TConcrete will be returned when it
is requested. The instance is cached according to the supplied lifestyle.
| |
RegisterTService(FuncTService, Lifestyle) |
Registers the specified delegate instanceCreator that will produce instances of
type TService and will be returned when an instance of type
TService is requested. The delegate is expected to produce new instances on
each call. The instances are cached according to the supplied lifestyle.
| |
RegisterTService, TImplementation |
Registers that a new instance of TImplementation will be returned every time a
TService is requested (transient).
| |
RegisterTService, TImplementation(Lifestyle) |
Registers that an instance of TImplementation will be returned when an
instance of type TService is requested. The instance is cached according to
the supplied lifestyle.
| |
RegisterCollection(Type, IEnumerableRegistration) | Obsolete.
Registers a collection of registrations, whose instances will be resolved lazily
each time the resolved collection of serviceType is enumerated.
The underlying collection is a stream that will return individual instances based on their
specific registered lifestyle, for each call to Current.
The order in which the types appear in the collection is the exact same order that the items were
supplied to this method, i.e the resolved collection is deterministic.
| |
RegisterCollection(Type, IEnumerableAssembly) | Obsolete.
Registers all concrete, non-generic types (both public and internal) that are defined in the given
set of assemblies and that implement the given serviceType
with a default lifestyle and register them as a collection of serviceType.
Unless overridden using a custom
LifestyleSelectionBehavior, the
default lifestyle is Transient.
Composites,
decorators and
generic type definitions
will be excluded from registration.
| |
RegisterCollection(Type, IEnumerableType) | Obsolete.
Registers a collection of serviceTypes, whose instances will be resolved lazily
each time the resolved collection of serviceType is enumerated.
The underlying collection is a stream that will return individual instances based on their
specific registered lifestyle, for each call to Current.
The order in which the types appear in the collection is the exact same order that the items were
supplied to this method, i.e the resolved collection is deterministic.
| |
RegisterCollection(Type, IEnumerable) | Obsolete.
Registers a dynamic (container uncontrolled) collection of elements of type
serviceType. A call to GetAllInstancesTService will return the
containerUncontrolledCollection itself, and updates to the collection will be
reflected in the result. If updates are allowed, make sure the collection can be iterated safely
if you're running a multi-threaded application.
| |
RegisterCollection(Type, Assembly) | Obsolete.
Registers all concrete, non-generic types (both public and internal) that are defined in the given
set of assemblies and that implement the given serviceType
with a default lifestyle and register them as a collection of serviceType.
Unless overridden using a custom
LifestyleSelectionBehavior, the
default lifestyle is Transient.
Composites,
decorators and
generic type definitions
will be excluded from registration.
| |
RegisterCollectionTService(IEnumerableAssembly) | Obsolete.
Registers all concrete, non-generic types (both public and internal) that are defined in the given
set of assemblies and that implement the given TService
with a default lifestyle and register them as a collection of TService.
Unless overridden using a custom
LifestyleSelectionBehavior, the
default lifestyle is Transient.
| |
RegisterCollectionTService(IEnumerableType) | Obsolete.
Registers a collection of serviceTypes, whose instances will be resolved lazily
each time the resolved collection of TService is enumerated.
The underlying collection is a stream that will return individual instances based on their
specific registered lifestyle, for each call to Current.
The order in which the types appear in the collection is the exact same order that the items were
supplied to this method, i.e the resolved collection is deterministic.
| |
RegisterCollectionTService(IEnumerableTService) | Obsolete.
Registers a dynamic (container-uncontrolled) collection of elements of type
TService. A call to GetAllInstancesTService will return the
containerUncontrolledCollection itself, and updates to the collection will be
reflected in the result. If updates are allowed, make sure the collection can be iterated safely
if you're running a multi-threaded application.
| |
RegisterCollectionTService(TService) | Obsolete.
Registers a collection of singleton elements of type TService.
| |
RegisterCollectionTService(IEnumerableRegistration) | Obsolete.
Registers a collection of registrations, whose instances will be resolved lazily
each time the resolved collection of TService is enumerated.
The underlying collection is a stream that will return individual instances based on their
specific registered lifestyle, for each call to Current.
The order in which the types appear in the collection is the exact same order that the items were
supplied to this method, i.e the resolved collection is deterministic.
| |
RegisterConditional(Type, Registration, PredicatePredicateContext) |
Conditionally registers that registration will be used every time a
serviceType is requested and where the supplied predicate
returns true. The predicate will only be evaluated a finite number of times; the predicate is
unsuited for making decisions based on runtime conditions.
| |
RegisterConditional(Type, Type, PredicatePredicateContext) |
Conditionally registers that a new instance of implementationType will be
returned every time a serviceType is requested (transient) and where the
supplied predicate returns true. The predicate will only be evaluated a finite
number of times; the predicate is unsuited for making decisions based on runtime conditions.
| |
RegisterConditional(Type, FuncTypeFactoryContext, Type, Lifestyle, PredicatePredicateContext) |
Conditionally registers that an instance of the type returned from
implementationTypeFactory will be returned every time a
serviceType is requested and where the supplied predicate
returns true. The instance is cached according to the supplied
lifestyle. Both the predicate and
implementationTypeFactory will only be evaluated a finite number of times;
they unsuited for making decisions based on runtime conditions.
| |
RegisterConditional(Type, Type, Lifestyle, PredicatePredicateContext) |
Conditionally registers that an instance of implementationType will be
returned every time a serviceType is requested and where the supplied
predicate returns true. The instance is cached according to the supplied
lifestyle. The predicate will only be evaluated a finite number of times; the
predicate is unsuited for making decisions based on runtime conditions.
| |
RegisterConditionalTService(Registration, PredicatePredicateContext) |
Conditionally registers that registration will be used every time a
TService requested and where the supplied predicate
returns true. The predicate will only be evaluated a finite number of times; the predicate is
unsuited for making decisions based on runtime conditions.
| |
RegisterConditionalTService, TImplementation(PredicatePredicateContext) |
Conditionally registers that a new instance of TImplementation will be
returned every time a TService is requested (transient) and where the
supplied predicate returns true. The predicate will only be evaluated a finite
number of times; the predicate is unsuited for making decisions based on runtime conditions.
| |
RegisterConditionalTService, TImplementation(Lifestyle, PredicatePredicateContext) |
Conditionally registers that an instance of TImplementation will be
returned every time a TService is requested and where the supplied
predicate returns true. The instance is cached according to the supplied
lifestyle. The predicate will only be evaluated a finite number of times; the
predicate is unsuited for making decisions based on runtime conditions.
| |
RegisterDecorator(Type, Type) |
Ensures that the supplied decoratorType decorator is returned, wrapping the
original registered serviceType, by injecting that service type into the
constructor of the supplied decoratorType. Multiple decorators may be applied
to the same serviceType. Decorators can be applied to both open, closed, and
non-generic service types. By default, a new decoratorType instance will be
returned on each request (according the Transient lifestyle),
independently of the lifestyle of the wrapped service.
| |
RegisterDecorator(Type, Type, Lifestyle) |
Ensures that the supplied decoratorType decorator is returned and cached with
the given lifestyle, wrapping the original registered
serviceType, by injecting that service type into the constructor of the
supplied decoratorType. Multiple decorators may be applied to the same
serviceType. Decorators can be applied to both open, closed, and non-generic
service types.
| |
RegisterDecorator(Type, Type, PredicateDecoratorPredicateContext) |
Ensures that the supplied decoratorType decorator is returned when the supplied
predicate returns true, wrapping the original registered
serviceType, by injecting that service type into the constructor of the
supplied decoratorType. Multiple decorators may be applied to the same
serviceType. Decorators can be applied to both open, closed, and non-generic
service types. By default, a new decoratorType instance will be returned on
each request (according the Transient lifestyle),
independently of the lifestyle of the wrapped service.
| |
RegisterDecorator(Type, FuncDecoratorPredicateContext, Type, Lifestyle, PredicateDecoratorPredicateContext) |
Ensures that the decorator type that is returned from decoratorTypeFactory is
supplied when the supplied predicate returns true and cached with the given
lifestyle, wrapping the original registered serviceType, by
injecting that service type into the constructor of the decorator type that is returned by the
supplied decoratorTypeFactory.
Multiple decorators may be applied to the same serviceType. Decorators can be
applied to both open, closed, and non-generic service types.
| |
RegisterDecorator(Type, Type, Lifestyle, PredicateDecoratorPredicateContext) |
Ensures that the supplied decoratorType decorator is returned when the supplied
predicate returns true and cached with the given
lifestyle, wrapping the original registered serviceType, by
injecting that service type into the constructor of the supplied decoratorType.
Multiple decorators may be applied to the same serviceType. Decorators can be
applied to both open, closed, and non-generic service types.
| |
RegisterDecoratorTService, TDecorator |
Ensures that the supplied TDecorator decorator is returned, wrapping the
original registered TService, by injecting that service type into the
constructor of the supplied TDecorator. Multiple decorators may be applied
to the same TService. By default, a new TDecorator
instance will be returned on each request (according the
Transient lifestyle), independently of the lifestyle of the
wrapped service.
| |
RegisterDecoratorTService, TDecorator(Lifestyle) |
Ensures that the supplied TDecorator decorator is returned and cached with
the given lifestyle, wrapping the original registered
TService, by injecting that service type into the constructor of the
supplied TDecorator. Multiple decorators may be applied to the same
TService. Decorators can be applied to both open, closed, and non-generic
service types.
| |
RegisterInitializer(ActionInstanceInitializationData, PredicateInitializerContext) |
Registers an ActionT delegate that runs after the
creation of instances for which the supplied predicate returns true. Please
note that only instances that are created by the container can be initialized this way.
| |
RegisterInitializerTService(ActionTService) |
Registers an ActionT delegate that runs after the creation of instances that
implement or derive from the given TService. Please note that only instances
that are created by the container (using constructor injection) can be initialized this way.
| |
RegisterInstance(Type, Object) |
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>).
| |
RegisterInstanceTService(TService) |
Registers a single instance that will be returned when an instance of type
TService 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<TService>(Func<TService>).
| |
RegisterSingleton(Type, IEnumerableAssembly) |
Registers all concrete, non-generic, public and internal types in the given set of
assemblies that implement the given openGenericServiceType
with Singleton lifestyle.
Decorators and
generic type definitions
will be excluded from registration, while
composites are included.
| |
RegisterSingleton(Type, FuncObject) |
Registers the specified delegate that allows constructing a single serviceType
instance. The container will call this delegate at most once during the lifetime of the application.
| |
RegisterSingleton(Type, Object) | Obsolete.
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.
| |
RegisterSingleton(Type, Assembly) |
Registers all concrete, non-generic, public and internal types in the given set of
assemblies that implement the given openGenericServiceType
with Singleton lifestyle.
Decorators and
generic type definitions
will be excluded from registration, while
composites are included.
| |
RegisterSingleton(Type, Type) |
Registers that the same instance of type implementationType will be returned every
time an instance of type serviceType type is requested. If
serviceType and implementationType represent the same type, the
type is registered by itself. implementationType must be thread-safe when working
in a multi-threaded environment. Open and closed generic types are supported.
| |
RegisterSingletonTConcrete |
Registers a single concrete instance that will be constructed using constructor injection and will
be returned when this instance is requested by type TConcrete.
This TConcrete must be thread-safe when working in a multi-threaded
environment.
If TConcrete implements IDisposable, a created instance will
get disposed when Container.Dispose gets called.
| |
RegisterSingletonTService(FuncTService) |
Registers the specified delegate that allows constructing a single instance of
TService. This delegate will be called at most once during the lifetime of
the application. The returned instance must be thread-safe when working in a multi-threaded
environment.
If the instance returned from instanceCreator implements IDisposable,
the created instance will get disposed when Container.Dispose
gets called.
| |
RegisterSingletonTService(TService) | Obsolete.
Registers a single instance that will be returned when an instance of type
TService 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 the overload that accepts a FuncTResult delegate.
| |
RegisterSingletonTService, TImplementation |
Registers that the same a single instance of type TImplementation will be
returned every time an TService type is requested. If
TService and TImplementation represent the same
type, the type is registered by itself. TImplementation must be thread-safe
when working in a multi-threaded environment.
If TImplementation implements IDisposable, a created instance will
get disposed when Container.Dispose gets called.
| |
ToString | Returns a string that represents the current object. (Inherited from ApiObject.) | |
Verify |
Verifies and diagnoses this Container instance. This method will call all registered
delegates, iterate registered collections and throws an exception if there was an error.
| |
Verify(VerificationOption) |
Verifies the Container. This method will call all registered delegates,
iterate registered collections and throws an exception if there was an error.
|
Name | Description | |
---|---|---|
ExpressionBuilding |
Occurs directly after the creation of the Expression of a registered type is made,
but before any initializer and lifestyle specific caching
has been applied, allowing the created Expression to be altered. Multiple delegates
may handle the same service type.
| |
ExpressionBuilt |
Occurs after the creation of the Expression of a registered type is complete (the
lifestyle has been applied), allowing the created Expression to be wrapped,
changed, or replaced. Multiple delegates may handle the same service type.
| |
ResolveUnregisteredType |
Occurs when an instance of a type is requested that has not been registered explicitly, allowing
resolution of unregistered types before the container tries to create the type.
|
Name | Description | |
---|---|---|
AppendToCollection(Type, Registration) | Overloaded.
Allows appending new registrations to existing registrations made using one of the
Collections.Register overloads.
(Defined by AdvancedExtensions.) | |
AppendToCollection(Type, Type) | Overloaded.
Allows appending new registrations to existing registrations made using one of the
Collections.Register overloads.
(Defined by AdvancedExtensions.) | |
EnableHttpRequestMessageTracking |
Makes the current HttpRequestMessage resolvable by calling
GetCurrentHttpRequestMessage.
(Defined by SimpleInjectorWebApiExtensions.) | |
GetCurrentHttpRequestMessage |
Retrieves the HttpRequestMessage instance for the current request.
(Defined by SimpleInjectorWebApiExtensions.) | |
GetItem |
Retrieves an item from the container stored by the given key or null when no
item is stored by that key.
(Defined by AdvancedExtensions.) | |
GetOrSetItemT |
Adds an item by the given key in the container by using the specified function,
if the key does not already exist. This operation is atomic.
(Defined by AdvancedExtensions.) | |
IsLocked |
Determines whether the specified container is locked making any new registrations. The container
is automatically locked when GetInstance is called for the
first time.
(Defined by AdvancedExtensions.) | |
IsVerifying | Determines whether the specified container is currently verifying its configuration. (Defined by AdvancedExtensions.) | |
RegisterWebApiControllers(HttpConfiguration) | Overloaded.
Registers the Web API IHttpController types that available for the application. This
method uses the configured IAssembliesResolver and
IHttpControllerTypeResolver to determine which controller types to register.
(Defined by SimpleInjectorWebApiExtensions.) | |
RegisterWebApiControllers(HttpConfiguration, Assembly) | Overloaded.
Registers the Web API IHttpController types that available for the application. This
method uses the configured IHttpControllerTypeResolver to determine which controller
types to register.
(Defined by SimpleInjectorWebApiExtensions.) | |
RegisterWebApiControllers(HttpConfiguration, IEnumerableAssembly) | Overloaded.
Registers the Web API IHttpController types that available for the application. This
method uses the configured IHttpControllerTypeResolver to determine which controller
types to register.
(Defined by SimpleInjectorWebApiExtensions.) | |
SetItem |
Stores an item by the given key in the container.
(Defined by AdvancedExtensions.) |
Name | Description | |
---|---|---|
IServiceProviderGetService | Gets the service object of the specified type. |
Thread-safety: Resolving instances can be done safely from multiple threads concurrently, but registration needs to be done from one single thread.
It is therefore safe to call GetInstance(Type), GetAllInstances(Type), GetService, GetRegistration(Type) and GetCurrentRegistrations and anything related to resolving instances from multiple thread concurrently. It is however unsafe to call RegisterXXX, ExpressionBuilding, ExpressionBuilt, ResolveUnregisteredType, AddRegistration(Type, Registration) or anything related to registering from multiple threads concurrently.