ContainerOptions Class

Simple Injector
Configuration options for the Container.
Inheritance Hierarchy


Namespace:  SimpleInjector
Assembly:  SimpleInjector (in SimpleInjector.dll) Version: 4.9.0

public class ContainerOptions : ApiObject

The ContainerOptions type exposes the following members.


Public propertyAllowOverridingRegistrations
Gets or sets a value indicating whether the container allows overriding registrations. The default is false.
Public propertyConstructorResolutionBehavior
Gets or sets the constructor resolution behavior. By default, the container only supports types that have a single public constructor.
Public propertyContainer
Gets the container to which this ContainerOptions instance belongs to.
Public propertyDefaultLifestyle
Gets or sets the default lifestyle that the container will use when a registration is made when no lifestyle is supplied.
Public propertyDefaultScopedLifestyle
Gets or sets the default scoped lifestyle that the container should use when a registration is made using Lifestyle.Scoped.
Public propertyDependencyInjectionBehavior
Gets or sets the dependency injection behavior.
Public propertyEnableAutoVerification
Gets or sets a value indicating whether the container should automatically trigger verification and diagnostics of its configuration when the first service is resolved (e.g. the first call to GetInstance). The behavior is identical to calling Verify() manually. The default is false.
Public propertyEnableDynamicAssemblyCompilation
Gets or sets a value indicating whether the container will use dynamic assemblies for compilation. By default, this value is true for the first few containers that are created in an AppDomain and false for all other containers. You can set this value explicitly to false to prevent the use of dynamic assemblies or you can set this value explicitly to true to force more container instances to use dynamic assemblies. Note that creating an infinite number of Container instances (for instance one per web request) with this property set to true will result in a memory leak; dynamic assemblies take up memory and will only be unloaded when the AppDomain is unloaded.
Public propertyLifestyleSelectionBehavior
Gets or sets the lifestyle selection behavior. The container's default behavior is to make registrations using the Transient lifestyle.
Public propertyPropertySelectionBehavior
Gets or sets the property selection behavior. The container's default behavior is to do no property injection.
Public propertyResolveUnregisteredCollections Obsolete.
Gets or sets a value indicating whether. This method is deprecated. Changing its value will have no effect.
Public propertyResolveUnregisteredConcreteTypes
Gets or sets a value indicating whether the container should resolve unregistered concrete types. The default value is
. Consider changing the value to
to prevent accidental creation of types you haven't registered explicitly.
Public propertySuppressLifestyleMismatchVerification
Gets or sets a value indicating whether the container should suppress checking for lifestyle mismatches (see: when a component is resolved. The default is false. This setting will have no effect when EnableAutoVerification is true.
Public propertyUseFullyQualifiedTypeNames
Gets or sets a value indicating whether all the containers in the current AppDomain should throw exceptions that contain fully qualified type name. The default is false which means the type's namespace is omitted.
Public propertyUseLoosenedLifestyleMismatchBehavior

Gets or sets a value indicating whether the container should use a loosened (i.e. less strict) behavior for detecting lifestyle mismatches (see: In short, when UseLoosenedLifestyleMismatchBehavior is set to trueTransient dependencies are allowed to be injected into Scoped components. When disabled, a warning would be given in that case.

Simple Injector allows custom lifestyles to be created and this loosened behavior works on custom lifestyles as well. The loosened behavior will ignore any lifestyle mismatch checks on any component with a lifestyle that has a Length that is equal or shorter than the length of Scoped.


Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from ApiObject.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from ApiObject.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from ApiObject.)
Public methodCode exampleRegisterResolveInterceptor
Public methodToString
Returns a string that represents the current object.
(Overrides ApiObjectToString.)

Public eventContainerLocking
Occurs just before the container is about to be locked, giving the developer a last change to interact and change the unlocked container before it is sealed for further modifications. Locking typically occurs by a call to Container.GetInstance, Container.Verify, or any other method that causes the construction and resolution of registered instances.

The following example shows the typical usage of the ContainerOptions class.
var container = new Container();

container.Register<ITimeProvider, DefaultTimeProvider>();

// Use of ContainerOptions class here.
container.Options.AllowOverridingRegistrations = true;

// Replaces the previous registration of ITimeProvider
container.Register<ITimeProvider, CustomTimeProvider>();
See Also