SimpleInjector The standard exception thrown when a container has an error in resolving an object. Initializes a new instance of the class. Initializes a new instance of the class with a specified error message. The message that describes the error. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. The error message that explains the reason for the exception. The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified. Initializes a new instance of the class with serialized data. The that holds the serialized object data about the exception being thrown. The that contains contextual information about the source or destination. The parameter is null. The class name is null or hresult is zero (0). Extension methods for enable advanced scenarios. Determines whether the specified container is locked making any new registrations. The container is automatically locked when GetInstance is called for the first time. The container. true if the specified container is locked; otherwise, false. Thrown when is null. Determines whether the specified container is currently verifying its configuration. The container. true if the specified container is verifying; otherwise, false. Thrown when is null. Retrieves an item from the container stored by the given or null when no item is stored by that key. Thread-safety: Calls to this method are thread-safe, but users should take proper percussions when they call both GetItem and . The container. The key of the item to retrieve. The stored item or null (Nothing in VB). Thrown when one of the supplied arguments is a null reference (Nothing in VB). Stores an item by the given in the container. Thread-safety: Calls to this method are thread-safe, but users should take proper percussions when they call both and SetItem. The container. The key of the item to insert or override. The actual item. May be null. Thrown when either or is a null reference (Nothing in VB). Adds an item by the given in the container by using the specified function, if the key does not already exist. This operation is atomic. The Type of the item to create. The container. The key of the item to insert or override. The function used to generate a value for the given key. The supplied value of will be supplied to the function when called. The stored item or the item from the . Thrown when either , or is a null reference (Nothing in VB). Allows appending new registrations to existing registrations made using one of the Collections.Register overloads. The container. The service type of the collection. The registration to append. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when the is not a reference type, is open generic, or ambiguous. Thrown when the container is locked. Thrown when the method is called for a registration that is made with one of the Collections.Register overloads that accepts a dynamic collection (an IEnumerable or IEnumerable<TService>). Allows appending new registrations to existing registrations made using one of the Collections.Register overloads. The container. The service type of the collection. The implementation type to append. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when the is not a reference type, or ambiguous. Thrown when the container is locked. Thrown when the method is called for a registration that is made with one of the Collections.Register overloads that accepts a dynamic collection (an IEnumerable or IEnumerable<TService>). Common base class for Simple Injector API classes. Gets the of the current instance. The instance that represents the exact runtime type of the current instance. Deprecation extensions. This interface method has been removed. Please call GetInstanceProducerFor instead. The behavior. The consumer. Throws an exception. This interface method has been removed. Please call SelectProperty(PropertyInfo) instead. The behavior. Type of the abstraction that is requested. The property to check. True when the property should be injected. Defines the container's behavior for finding a suitable constructor for the creation of a type. Set the ConstructorResolutionBehavior property of the container's property to change the default behavior of the container. Gets the given 's constructor that can be used by the container to create that instance. Type of the implementation to find a suitable constructor for. The . This method never returns null. Thrown when no suitable constructor could be found. Defines the container's behavior for building an expression tree for an dependency to inject, based on the information of the consuming type the dependency is injected into. Set the ConstructorInjectionBehavior property of the container's property to change the default behavior of the container. Verifies the specified . Contextual information about the consumer where the built dependency is injected into. Thrown when the type of the target supplied with the supplied cannot be used for auto wiring. Thrown when the supplied argument is a null reference. Gets the for the Target of the supplied . Contextual information about the consumer where the built dependency is injected into. The indication whether the method should return null or throw an exception when the type is not registered. An that describes the intend of creating that Target. This method never returns null. Thrown when the argument is a null reference. Defines the container's behavior for selecting the lifestyle for a registration in case no lifestyle is explicitly supplied. Set the LifestyleSelectionBehavior property of the container's property to change the default behavior of the container. By default, when no lifestyle is explicitly supplied, the Transient lifestyle is used. Selects the lifestyle based on the supplied type information. Type of the implementation to that is registered. The suited for the given type. Thrown when either one of the arguments is a null reference. An instance of this type will be supplied to the delegate that is that is supplied to the RegisterResolveInterceptor method that takes this delegate. This type contains contextual information about a resolved type and it allows the user to examine the given instance to decide whether the should be applied or not. Gets the that is responsible for the initialization of the created instance. The or null (Nothing in VB) when the instance producer is unknown. Gets the that is responsible for the initialization of the created instance. /// The . An instance of this type will be supplied to the delegate that is that is supplied to the RegisterInitializer overload that takes this delegate. This type contains contextual information about the creation and it allows the user to examine the given instance to decide whether the instance should be initialized or not. Gets a null reference. This property has been deprecated. The null (Nothing in VB). Gets the that is responsible for the initialization of the created instance. /// The . Contains data that can be used to initialize a created instance. This data includes the actual created and the information about the created instance. Initializes a new instance of the struct. The that contains contextual information about the created instance. The created instance. Gets the with contextual information about the created instance. The . Gets the created instance. The created instance. Indicates whether the values of two specified objects are equal. The first object to compare. The second object to compare. True if a and b are equal; otherwise, false. Indicates whether the values of two specified objects are not equal. The first object to compare. The second object to compare. True if a and b are not equal; otherwise, false. This is an internal type. Only depend on this type when you want to be absolutely sure a future version of the framework will break your code. Initializes a new instance of the struct. The scope factory. The container. Gets the lazily initialized Scope of the current LazyScope instance. The current Scope or null. This is an internal type. Only depend on this type when you want to be absolutely sure a future version of the framework will break your code. Implementation type. Initializes a new instance of the struct. The registration. Gets the lazily initialized instance for the of the current LazyScopedRegistration. The scope that is used to retrieve the instance. The cached instance. Defines the container's behavior for selecting properties to inject during the creation of a type. Set the PropertySelectionBehavior property of the container's property to change the default behavior of the container. By default, no properties will be injected by the container. Determines whether a property should be injected by the container upon creation of its type. The type being created for which the property should be injected. Note that this might a different type than the type on which the property is declared (which might be a base class). The property to check. True when the property should be injected. A known relationship defines a relationship between two types. The Diagnostics Debug View uses this information to spot possible misconfigurations. Initializes a new instance of the class. The implementation type of the parent type. The lifestyle of the parent type. The type that the parent depends on (it is injected into the parent). Gets the implementation type of the parent type of the relationship. The implementation type of the parent type of the relationship. Gets the lifestyle of the parent type of the relationship. The lifestyle of the parent type of the relationship. Gets the type that the parent depends on (it is injected into the parent). The type that the parent depends on. The container. Create an instance of this type for registration of dependencies. 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 , , GetService, and and anything related to resolving instances from multiple thread concurrently. It is however unsafe to call RegisterXXX, , , , or anything related to registering from multiple threads concurrently. Common Container methods specific for the full .NET version of Simple Injector. Methods for batch registration. Methods for registration of collections. Methods for conditional registrations. These conditional registration methods lack a Func{PredicateContext, TService} predicate method. This is deliberate, because would force the factory to be registered as transient, forcing the whole parent structure to become transient as well. Besides this, it would blind the diagnostic system, because it will stop at the delegate, instead of being able to analyze the object graph as a whole. Methods for registration. Methods for registration of decorators. Methods for resolving instances. Methods for verifying the container. Initializes a new instance of the class. Gets the container options. The instance for this container. 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. The instance for this container. Gets a value indicating whether the container is currently being verified on the current thread. True in case the container is currently being verified on the current thread; otherwise false. Gets the intermediate lifestyle that forwards CreateRegistration calls to the lifestyle that is returned from the registered container.Options.LifestyleSelectionBehavior. 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 event), and requested unregistered collections. Note that the result of this method may change over time, because of these implicit registrations. This method has a performance characteristic of O(n). Prevent from calling this in a performance critical path of the application. Note: This method is not guaranteed to always return the same instance for a given registration. It will however either always return a producer that is able to return the expected instance. Because of this, do not compare sets of instances returned by different calls to by reference. The way of comparing lists is by the actual type. The type of each instance is guaranteed to be unique in the returned list. An array of instances. 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. This method has a performance characteristic of O(n). Prevent from calling this in a performance critical path of the application. This list contains the root objects of 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 event), and requested unregistered collections. Note that the result of this method may change over time, because of these implicit registrations. Note: This method is not guaranteed to always return the same instance for a given registration. It will however either always return a producer that is able to return the expected instance. Because of this, do not compare sets of instances returned by different calls to by reference. The way of comparing lists is by the actual type. The type of each instance is guaranteed to be unique in the returned list. An array of instances. Thrown when this method is called before has been successfully called. Releases all instances that are cached by the object. Prevents any new registrations to be made to the container. Releases all instances that are cached by the object. True for a normal dispose operation; false to finalize the handle. Registers all concrete, non-generic, public and internal types in the given set of that implement the given with container's default lifestyle (which is transient by default). Decorators and generic type definitions will be excluded from registration, while composites are included. The definition of the open generic type. A list of assemblies that will be searched. Thrown when one of the arguments contain a null reference (Nothing in VB). Thrown when is not an open generic type. Thrown when the given set of contain multiple types that implement the same closed generic version of the given . Registers all concrete, non-generic, public and internal types in the given set of that implement the given with container's default lifestyle (which is transient by default). Decorators and generic type definitions will be excluded from registration, while composites are included. The definition of the open generic type. A list of assemblies that will be searched. Thrown when one of the arguments contain a null reference (Nothing in VB). Thrown when is not an open generic type. Thrown when the given set of contain multiple types that implement the same closed generic version of the given . Registers all concrete, non-generic, public and internal types in the given that implement the given with the supplied . Decorators and generic type definitions will be excluded from registration, while composites are included. The definition of the open generic type. An assembly that will be searched. The lifestyle to register instances with. Thrown when one of the arguments contain a null reference (Nothing in VB). Thrown when is not an open generic type. Thrown when the given contain multiple types that implement the same closed generic version of the given . Registers all concrete, non-generic, public and internal types in the given set of that implement the given with the supplied . Decorators and generic type definitions will be excluded from registration, while composites are included. The definition of the open generic type. A list of assemblies that will be searched. The lifestyle to register instances with. Thrown when one of the arguments contain a null reference (Nothing in VB). Thrown when is not an open generic type. Thrown when the given set of contain multiple types that implement the same closed generic version of the given . Registers all supplied based on the closed-generic version of the given with the transient lifestyle. The definition of the open generic type. A list types to be registered. Thrown when one of the arguments contain a null reference (Nothing in VB). Thrown when is not an open generic type or when one of the supplied types from the collection does not derive from . Thrown when the given set of contain multiple types that implement the same closed generic version of the given . Registers all supplied based on the closed-generic version of the given with the given . The definition of the open generic type. A list types to be registered. The lifestyle to register instances with. Thrown when one of the arguments contain a null reference (Nothing in VB). Thrown when is not an open generic type or when one of the supplied types from the collection does not derive from . Thrown when the given set of contain multiple types that implement the same closed generic version of the given . Registers all concrete, non-generic, public and internal types in the given set of that implement the given with lifestyle. Decorators and generic type definitions will be excluded from registration, while composites are included. The definition of the open generic type. A list of assemblies that will be searched. Thrown when one of the arguments contain a null reference (Nothing in VB). Thrown when is not an open generic type. Thrown when the given set of contain multiple types that implement the same closed generic version of the given . Registers all concrete, non-generic, public and internal types in the given set of that implement the given with lifestyle. Decorators and generic type definitions will be excluded from registration, while composites are included. The definition of the open generic type. A list of assemblies that will be searched. Thrown when one of the arguments contain a null reference (Nothing in VB). Thrown when is not an open generic type. Thrown when the given set of contain multiple types that implement the same closed generic version of the given . Registers all concrete, non-generic types (both public and internal) that are defined in the given set of and that implement the given with a default lifestyle and register them as a collection of . Unless overridden using a custom LifestyleSelectionBehavior, the default lifestyle is Transient. The element type of the collections to register. This can be either a non-generic, closed-generic or open-generic type. A list of assemblies that will be searched. Thrown when one of the supplied arguments contain a null reference (Nothing in VB). Registers all concrete, non-generic types (both public and internal) that are defined in the given set of and that implement the given with a default lifestyle and register them as a collection of . Unless overridden using a custom LifestyleSelectionBehavior, the default lifestyle is Transient. Composites, decorators and generic type definitions will be excluded from registration. The element type of the collections to register. This can be either a non-generic, closed-generic or open-generic type. A list of assemblies that will be searched. Thrown when one of the supplied arguments contain a null reference (Nothing in VB). Registers all concrete, non-generic types (both public and internal) that are defined in the given set of and that implement the given with a default lifestyle and register them as a collection of . Unless overridden using a custom LifestyleSelectionBehavior, the default lifestyle is Transient. Composites, decorators and generic type definitions will be excluded from registration. The element type of the collections to register. This can be either a non-generic, closed-generic or open-generic type. A list of assemblies that will be searched. Thrown when one of the supplied arguments contain a null reference (Nothing in VB). Returns all concrete non-generic types that are located in the supplied and implement or inherit from the supplied . Use this method when you need influence the types that are registered using Container.Collections.Register. The Collections.Register overloads that take a collection of objects use this method internally to get the list of types that need to be registered. Instead of calling such overload, you can call an overload that takes a list of objects and pass in a filtered result from this GetTypesToRegister method. assemblies = new[] { typeof(ILogger).Assembly }; var types = container.GetTypesToRegister(assemblies) .Where(type => type.IsPublic); container.Collections.Register(types); ]]> This example calls the GetTypesToRegister method to request a list of concrete implementations of the ILogger interface from the assembly of that interface. After that all internal types are filtered out. This list is supplied to the Collections.Register<TService>(IEnumerable<Type>) overload to finish the registration. The base type or interface to find derived types for. A list of assemblies that will be searched. A collection of types. Thrown when one of the arguments contain a null reference (Nothing in VB). A collection of types. Returns all concrete non-generic types that are located in the supplied and implement or inherit from the supplied . Use this method when you need influence the types that are registered using Container.Collections.Register. The Collections.Register overloads that take a collection of objects use this method internally to get the list of types that need to be registered. Instead of calling such overload, you can call an overload that takes a list of objects and pass in a filtered result from this GetTypesToRegister method. ( typeof(ILogger).Assembly, typeof(FileLogger).Assembly) .Where(type => type.IsPublic); container.Collections.Register(types); ]]> This example calls the GetTypesToRegister method to request a list of concrete implementations of the ILogger interface from the assembly of that interface. After that all internal types are filtered out. This list is supplied to the Container.Collections.Register<TService>(IEnumerable<Type>) overload to finish the registration. The base type or interface to find derived types for. A list of assemblies that will be searched. A collection of types. Thrown when one of the arguments contain a null reference (Nothing in VB). A collection of types. Returns all concrete non-generic types that are located in the supplied and implement or inherit from the supplied . can be an open-generic type. Use this method when you need influence the types that are registered using Register or Collections.Register. The Register overloads that take a collection of objects use this method internally to get the list of types that need to be registered. Instead of calling such overload, you can call an overload that takes a list of objects and pass in a filtered result from this GetTypesToRegister method. ).Assembly }; var types = container.GetTypesToRegister(typeof(ICommandHandler<>), assemblies) .Where(type => type.IsPublic); container.Register(typeof(ICommandHandler<>), types); ]]> This example calls the GetTypesToRegister method to request a list of concrete implementations of the ICommandHandler<T> interface from the assembly of that interface. After that all internal types are filtered out. This list is supplied to the Register(Type, IEnumerable<Type>) overload to finish the registration. The base type or interface to find derived types for. This can be both a non-generic and open-generic type. A list of assemblies that will be searched. A collection of types. Thrown when one of the arguments contain a null reference (Nothing in VB). Returns all concrete non-generic types that are located in the supplied and implement or inherit from the supplied . can be an open-generic type. Use this method when you need influence the types that are registered using Register or Collections.Register. The Register overloads that take a collection of objects use this method internally to get the list of types that need to be registered. Instead of calling such overload, you can call an overload that takes a list of objects and pass in a filtered result from this GetTypesToRegister method. ).Assembly }; var types = container.GetTypesToRegister(typeof(ICommandHandler<>), assemblies) .Where(type => type.IsPublic); container.Register(typeof(ICommandHandler<>), types); ]]> This example calls the GetTypesToRegister method to request a list of concrete implementations of the ICommandHandler<T> interface from the assembly of that interface. After that all internal types are filtered out. This list is supplied to the Register(Type, IEnumerable<Type>) overload to finish the registration. The base type or interface to find derived types for. This can be both a non-generic and open-generic type. A list of assemblies that will be searched. A collection of types. Thrown when one of the arguments contain a null reference (Nothing in VB). Returns all concrete types that are located in the supplied and implement or inherit from the supplied and match the specified . can be an open-generic type. Use this method when you need influence the types that are registered using Register. The Register overloads that take a collection of objects use this method internally to get the list of types that need to be registered. Instead of calling such overload, you can call an overload that takes a list of objects and pass in a filtered result from this GetTypesToRegister method. ).Assembly }; var options = new TypesToRegisterOptions { IncludeGenericTypeDefinitions: true }; var types = container.GetTypesToRegister(typeof(ICommandHandler<>), assemblies, options) .Where(type => type.IsPublic); container.Register(typeof(ICommandHandler<>), types); ]]> This example calls the GetTypesToRegister method to request a list of concrete implementations of the ICommandHandler<T> interface from the assembly of that interface. After that all internal types are filtered out. This list is supplied to the Register(Type, IEnumerable<Type>) overload to finish the registration. The base type or interface to find derived types for. This can be both a non-generic and open-generic type. A list of assemblies that will be searched. The options. A collection of types. Thrown when one of the arguments contain a null reference (Nothing in VB). Registers a dynamic (container-uncontrolled) collection of elements of type . A call to will return the 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. The interface or base type that can be used to retrieve instances. The container-uncontrolled collection to register. Thrown when this container instance is locked and can not be altered, or when a for has already been registered. Thrown when is a null reference. Registers a collection of singleton elements of type . The interface or base type that can be used to retrieve instances. The collection to register. Thrown when this container instance is locked and can not be altered, or when a for has already been registered. Thrown when is a null reference. Thrown when one of the elements of is a null reference. Registers a collection of , whose instances will be resolved lazily each time the resolved collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. Thrown when is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element, a generic type definition, or the is not assignable from one of the given elements. Registers a collection of , whose instances will be resolved lazily each time the resolved collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element or when is not assignable from any of the service types supplied by the given instances. Registers a collection of , whose instances will be resolved lazily each time the resolved collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element, a generic type definition, or the is not assignable from one of the given elements. Registers a collection of , whose instances will be resolved lazily each time the resolved collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. This can be an a non-generic type, closed generic type or generic type definition. The collection of objects whose instances will be requested from the container. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element or when is not assignable from any of the service types supplied by the given instances. Registers a dynamic (container uncontrolled) collection of elements of type . A call to will return the 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. The base type or interface for elements in the collection. The collection of items to register. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when represents an open generic type. Conditionally registers that a new instance of will be returned every time a is requested (transient) and where the supplied returns true. The predicate will only be evaluated a finite number of times; the predicate is unsuited for making decisions based on runtime conditions. This method uses the container's LifestyleSelectionBehavior to select the exact lifestyle for the specified type. By default this will be Transient. The interface or base type that can be used to retrieve the instances. The concrete type that will be registered. The predicate that determines whether the can be applied for the requested service type. This predicate can be used to build a fallback mechanism where multiple registrations for the same service type are made. Note that the predicate will be called a finite number of times and its result will be cached for the lifetime of the container. It can't be used for selecting a type based on runtime conditions. Thrown when one of the arguments is a null reference (Nothing in VB). Thrown when this container instance is locked and can not be altered. Conditionally registers that an instance of will be returned every time a is requested and where the supplied returns true. The instance is cached according to the supplied . The predicate will only be evaluated a finite number of times; the predicate is unsuited for making decisions based on runtime conditions. The interface or base type that can be used to retrieve the instances. The concrete type that will be registered. The lifestyle that specifies how the returned instance will be cached. The predicate that determines whether the can be applied for the requested service type. This predicate can be used to build a fallback mechanism where multiple registrations for the same service type are made. Note that the predicate will be called a finite number of times and its result will be cached for the lifetime of the container. It can't be used for selecting a type based on runtime conditions. Thrown when one of the arguments is a null reference (Nothing in VB). Thrown when this container instance is locked and can not be altered. Conditionally registers that a new instance of will be returned every time a is requested (transient) and where the supplied returns true. The predicate will only be evaluated a finite number of times; the predicate is unsuited for making decisions based on runtime conditions. This method uses the container's LifestyleSelectionBehavior to select the exact lifestyle for the specified type. By default this will be Transient. The base type or interface to register. This can be an open-generic type. The actual type that will be returned when requested. The predicate that determines whether the can be applied for the requested service type. This predicate can be used to build a fallback mechanism where multiple registrations for the same service type are made. Note that the predicate will be called a finite number of times and its result will be cached for the lifetime of the container. It can't be used for selecting a type based on runtime conditions. Thrown when one of the arguments is a null reference (Nothing in VB). Thrown when this container instance is locked and can not be altered. Conditionally registers that an instance of will be returned every time a is requested and where the supplied returns true. The instance is cached according to the supplied . The predicate will only be evaluated a finite number of times; the predicate is unsuited for making decisions based on runtime conditions. The base type or interface to register. This can be an open-generic type. The actual type that will be returned when requested. The lifestyle that defines how returned instances are cached. The predicate that determines whether the can be applied for the requested service type. This predicate can be used to build a fallback mechanism where multiple registrations for the same service type are made. Note that the predicate will be called a finite number of times and its result will be cached for the lifetime of the container. It can't be used for selecting a type based on runtime conditions. Thrown when one of the arguments is a null reference (Nothing in VB). Thrown when and are not a generic type or when is a partially-closed generic type. Thrown when this container instance is locked and can not be altered. Conditionally registers that an instance of the type returned from will be returned every time a is requested and where the supplied returns true. The instance is cached according to the supplied . Both the and will only be evaluated a finite number of times; they unsuited for making decisions based on runtime conditions. The base type or interface to register. This can be an open-generic type. A factory that allows building Type objects that define the implementation type to inject, based on the given contextual information. The delegate is allowed to return (partially) open-generic types. The lifestyle that defines how returned instances are cached. The predicate that determines whether the registration can be applied for the requested service type. This predicate can be used to build a fallback mechanism where multiple registrations for the same service type are made. Note that the predicate will be called a finite number of times and its result will be cached for the lifetime of the container. It can't be used for selecting a type based on runtime conditions. Thrown when one of the arguments is a null reference (Nothing in VB). Thrown when is a partially-closed generic type. Thrown when this container instance is locked and can not be altered. Conditionally registers that will be used every time a requested and where the supplied returns true. The predicate will only be evaluated a finite number of times; the predicate is unsuited for making decisions based on runtime conditions. The base type or interface to register. This can be an open-generic type. The instance to register. The predicate that determines whether the can be applied for the requested service type. This predicate can be used to build a fallback mechanism where multiple registrations for the same service type are made. Note that the predicate will be called a finite number of times and its result will be cached for the lifetime of the container. It can't be used for selecting a type based on runtime conditions. Thrown when one of the arguments is a null reference (Nothing in VB). Thrown when this container instance is locked and can not be altered. Conditionally registers that will be used every time a is requested and where the supplied returns true. The predicate will only be evaluated a finite number of times; the predicate is unsuited for making decisions based on runtime conditions. The base type or interface to register. This can be an open-generic type. The instance to register. The predicate that determines whether the can be applied for the requested service type. This predicate can be used to build a fallback mechanism where multiple registrations for the same service type are made. Note that the predicate will be called a finite number of times and its result will be cached for the lifetime of the container. It can't be used for selecting a type based on runtime conditions. Thrown when one of the arguments is a null reference (Nothing in VB). Thrown when is open generic or is not assignable to . Thrown when this container instance is locked and can not be altered. 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. The event is called by the container every time an unregistered type is requested for the first time, allowing a developer to do unregistered type resolution. By calling the Register method on the , a , or delegate can be registered allowing the container to retrieve instances of the requested type. This registration is cached and it prevents the ResolveUnregisteredType event from being called again for the same type. When no registered event handled the registration of an unregistered type, the container will try to create the type when this type is either concrete or is the interface. Concrete types will be registered with the Transient lifestyle and registrations will return an empty collection. When no even handled the registration and the container could not create it, an exception is thrown. Thread-safety: Please note that the container will not ensure that the hooked delegates are executed only once. While the calls to for a given type are finite (and will in most cases happen just once), a container can call the delegate multiple times and make parallel calls to the delegate. You must make sure that the code can be called multiple times and is thread-safe. The following example shows the usage of the event: { void Validate(T instance); } // Implementation of the null object pattern. public class EmptyValidator : IValidator { public void Validate(T instance) { // Does nothing. } } [TestMethod] public void TestResolveUnregisteredType() { // Arrange var container = new Container(); // Register an EmptyValidator to be returned when a IValidator is requested: container.ResolveUnregisteredType += (sender, e) => { if (e.UnregisteredServiceType.IsGenericType && e.UnregisteredServiceType.GetGenericTypeDefinition() == typeof(IValidator<>)) { var validatorType = typeof(EmptyValidator<>).MakeGenericType( e.UnregisteredServiceType.GetGenericArguments()); // Register the instance as singleton. e.Register(Lifestyle.Singleton.CreateRegistration(validatorType, container)); } }; // Act var orderValidator = container.GetInstance>(); var customerValidator = container.GetInstance>(); // Assert Assert.IsInstanceOfType(orderValidator, typeof(EmptyValidator)); Assert.IsInstanceOfType(customerValidator, typeof(EmptyValidator)); } ]]> The example above registers a delegate that is raised every time an unregistered type is requested from the container. The delegate checks whether the requested type is a closed generic implementation of the IValidator<T> interface (such as IValidator<Order> or IValidator<Customer>). In that case it will request the container for a concrete EmptyValidator<T> implementation that implements the given UnregisteredServiceType, and registers a delegate that will return this created instance. The e.Register call registers the method in the container, preventing the from being called again for the exact same service type, preventing any performance penalties. Please note that given example is just an uhhmm... example. In the case of the example the EmptyValidator<T> can be better registered using of the built-in Register methods instead. These methods take care of any given generic type constraint and allow the implementation to be integrated into the container's pipeline, which allows it to be intercepted using the event and allow any registered initializers to be applied. Occurs after the creation of the of a registered type is complete (the lifestyle has been applied), allowing the created to be wrapped, changed, or replaced. Multiple delegates may handle the same service type. The ExpressionBuilt event is called by the container every time an registered type is getting compiled, allowing a developer to change the way the type is created. The delegate that hooks to the ExpressionBuilt event, can change the property on the , which allows changing the way the type is constructed. Thread-safety: Please note that the container will not ensure that the hooked delegates are executed only once per service type. While the calls to for a given type are finite (and will in most cases happen just once), a container can call the delegate multiple times and make parallel calls to the delegate. You must make sure that the code can be called multiple times and is thread-safe. The following example shows the usage of the ExpressionBuilt event: { void Validate(T instance); } public interface ILogger { void Write(string message); } // Implementation of the decorator pattern. public class MonitoringValidator : IValidator { private readonly IValidator validator; private readonly ILogger logger; public MonitoringValidator(IValidator validator, ILogger logger) { this.validator = validator; this.logger = logger; } public void Validate(T instance) { this.logger.Write("Validating " + typeof(T).Name); this.validator.Validate(instance); this.logger.Write("Validated " + typeof(T).Name); } } [TestMethod] public void TestExpressionBuilt() { // Arrange var container = new Container(); container.Register(Lifestyle.Singleton); container.Register, OrderValidator>(); container.Register, CustomerValidator>(); // Intercept the creation of IValidator instances and wrap them in a MonitoringValidator: container.ExpressionBuilt += (sender, e) => { if (e.RegisteredServiceType.IsGenericType && e.RegisteredServiceType.GetGenericTypeDefinition() == typeof(IValidator<>)) { var decoratorType = typeof(MonitoringValidator<>) .MakeGenericType(e.RegisteredServiceType.GetGenericArguments()); // Wrap the IValidator in a MonitoringValidator. e.Expression = Expression.New(decoratorType.GetConstructors()[0], new Expression[] { e.Expression, container.GetRegistration(typeof(ILogger)).BuildExpression(), }); } }; // Act var orderValidator = container.GetInstance>(); var customerValidator = container.GetInstance>(); // Assert Assert.IsInstanceOfType(orderValidator, typeof(MonitoringValidator)); Assert.IsInstanceOfType(customerValidator, typeof(MonitoringValidator)); } ]]> The example above registers a delegate that is raised every time the container compiles the expression for an registered type. The delegate checks whether the requested type is a closed generic implementation of the IValidator<T> interface (such as IValidator<Order> or IValidator<Customer>). In that case it will changes the current with a new one that creates a new MonitoringValidator<T> that takes the current validator (and an ILogger) as an dependency. Please note that given example is just an uhhmm... example. In the case of the example the MonitoringValidator<T> is a decorator and instead of manually writing this code that many limitations, you can use one of the built-in RegisterDecorator methods instead. These extension methods take care of any given generic type constraint, allow to register decorators conditionally and allow the decorator to be integrated into the container's pipeline, which allows it to be intercepted using the event and allow any registered initializers to be applied. Occurs directly after the creation of the of a registered type is made, but before any initializer and lifestyle specific caching has been applied, allowing the created to be altered. Multiple delegates may handle the same service type. The ExpressionBuilding event is called by the container every time an registered type is getting compiled, allowing a developer to change the way the type is created. The delegate that hooks to the ExpressionBuilding event, can change the property on the , which allows changing the way the type is constructed. The exact type supplied depends on the type of registration. Registrations that explicitly supply the implementation type (such as Register<TService, TImplementation>()) will result in an , while registrations that take a delegate (such as Register<TService>(Func<TService>)) will result in an . Singletons that are passed in using their value (RegisterInstance<TService>(TService)) will result in an . Note that other ExpressionBuilding registrations might have changed the property and might have supplied an of a different type. The order in which these events are registered might be of importance to you. Thread-safety: Please note that the container will not ensure that the hooked delegates are executed only once per service type. While the calls to registered ExpressionBuilding events for a given type are finite (and will in most cases happen just once), a container can call the delegate multiple times and make parallel calls to the delegate. You must make sure that the code can be called multiple times and is thread-safe. The following example shows the usage of the ExpressionBuilding event: { var expression = e.Expression as NewExpression; if (expression != null) { var propertiesToInject = from property in expression.Constructor.DeclaringType.GetProperties() where property.GetCustomAttributes(typeof(MyInjectPropertyAttribute), true).Any() let registration = container.GetRegistration(property.PropertyType, true) select Tuple.Create(property, registration); if (propertiesToInject.Any()) { Func[], object> injectorDelegate = (instance, dependencies) => { foreach (var dependency in dependencies) { dependency.Item1.SetValue(instance, dependency.Item2.GetInstance(), null); } return instance; }; e.Expression = Expression.Convert( Expression.Invoke( Expression.Constant(injectorDelegate), e.Expression, Expression.Constant(propertiesToInject.ToArray())), expression.Constructor.DeclaringType); } } }; } ]]> The example above registers a delegate that is raised every time the container compiles the expression for an registered type. The delegate checks if the type contains properties that are decorated with the supplied MyInjectPropertyAttribute. If decorated properties are found, the given expression is replaced with an expression that injects decorated properties. Gets the object that allows access to methods related to registration and creation of collections. The instance for this container. This property is obsolete. Please use instead. The instance for this container. Registers that a new instance of will be returned every time it is requested (transient). This method uses the container's LifestyleSelectionBehavior to select the exact lifestyle for the specified type. By default this will be Transient. The concrete type that will be registered. Thrown when this container instance is locked and can not be altered, or when an the has already been registered. Thrown when the is a type that can not be created by the container. Registers that an instance of will be returned when it is requested. The instance is cached according to the supplied . The concrete type that will be registered. The lifestyle that specifies how the returned instance will be cached. Thrown when this container instance is locked and can not be altered, or when an the has already been registered. Thrown when the is a type that can not be created by the container. Registers that a new instance of will be returned every time a is requested (transient). This method uses the container's LifestyleSelectionBehavior to select the exact lifestyle for the specified type. By default this will be Transient. The interface or base type that can be used to retrieve the instances. The concrete type that will be registered. Thrown when this container instance is locked and can not be altered, or when an the has already been registered. Thrown when the given type is not a type that can be created by the container. Registers that an instance of will be returned when an instance of type is requested. The instance is cached according to the supplied . The interface or base type that can be used to retrieve the instances. The concrete type that will be registered. The lifestyle that specifies how the returned instance will be cached. Thrown when this container instance is locked and can not be altered, or when an the has already been registered. Thrown when the given type is not a type that can be created by the container. Registers the specified delegate that allows returning transient instances of . The delegate is expected to always return a new instance on each call. This method uses the container's LifestyleSelectionBehavior to select the exact lifestyle for the specified type. By default this will be Transient. The interface or base type that can be used to retrieve instances. The delegate that allows building or creating new instances. Thrown when this container instance is locked and can not be altered, or when the has already been registered. Thrown when is a null reference. Registers the specified delegate that will produce instances of type and will be returned when an instance of type is requested. The delegate is expected to produce new instances on each call. The instances are cached according to the supplied . The interface or base type that can be used to retrieve instances. The delegate that allows building or creating new instances. The lifestyle that specifies how the returned instance will be cached. Thrown when this container instance is locked and can not be altered, or when the has already been registered. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Registers that a new instance of will be returned every time it is requested (transient). This method uses the container's LifestyleSelectionBehavior to select the exact lifestyle for the specified type. By default this will be Transient. The concrete type that will be registered. This can be an open-generic type. Thrown when is a null references (Nothing in VB). Thrown when represents a type that can not be created by the container. Thrown when this container instance is locked and can not be altered, or when an the has already been registered. Registers that a new instance of will be returned every time a is requested. If and represent the same type, the type is registered by itself. Open and closed generic types are supported. This method uses the container's LifestyleSelectionBehavior to select the exact lifestyle for the specified type. By default this will be Transient. The base type or interface to register. This can be an open-generic type. The actual type that will be returned when requested. This can be an open-generic type. Thrown when or are null references (Nothing in VB). Thrown when is no sub type from (or the same type). Thrown when this container instance is locked and can not be altered, or when an the has already been registered. Registers that an instance of type will be returned when an instance of type is requested. The instance is cached according to the supplied . Open and closed generic types are supported. The interface or base type that can be used to retrieve the instances. This can be an open-generic type. The concrete type that will be registered. This can be an open-generic type. The lifestyle that specifies how the returned instance will be cached. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when this container instance is locked and can not be altered, or when the has already been registered. Thrown when the given type is not a type that can be created by the container, when either or are open generic types, or when is not assignable from the . Thrown when one of the supplied arguments is a null reference (Nothing in VB). Registers the specified delegate that allows returning instances of . This method uses the container's LifestyleSelectionBehavior to select the exact lifestyle for the specified type. By default this will be Transient. The base type or interface to register. The delegate that will be used for creating new instances. Thrown when either or are null references (Nothing in VB). Thrown when represents an open generic type. Thrown when this container instance is locked and can not be altered, or when an the has already been registered. Registers the specified delegate that will produce instances of type and will be returned when an instance of type is requested. The delegate is expected to produce new instances on each call. The instances are cached according to the supplied . The interface or base type that can be used to retrieve instances. The delegate that allows building or creating new instances. The lifestyle that specifies how the returned instance will be cached. Thrown when this container instance is locked and can not be altered, or when the has already been registered. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Registers a single instance that will be returned when an instance of type is requested. This 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 delegate. The interface or base type that can be used to retrieve the instance. The instance to register. Thrown when this container instance is locked and can not be altered, or when the has already been registered. Thrown when is a null reference. Registers a single instance that will be returned when an instance of type is requested. This 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>). The interface or base type that can be used to retrieve the instance. The instance to register. Thrown when this container instance is locked and can not be altered, or when the has already been registered. Thrown when is a null reference. Registers a single instance that will be returned when an instance of type is requested. This must be thread-safe when working in a multi-threaded environment. The base type or interface to register. The instance to register. Thrown when either or are null references (Nothing in VB). Thrown when is no sub type from . Thrown when this container instance is locked and can not be altered, or when an the has already been registered. Registers a single instance that will be returned when an instance of type is requested. This 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>). The base type or interface to register. The instance to register. Thrown when either or are null references (Nothing in VB). Thrown when is no sub type from . Thrown when this container instance is locked and can not be altered, or when an the has already been registered. Registers a single concrete instance that will be constructed using constructor injection and will be returned when this instance is requested by type . This must be thread-safe when working in a multi-threaded environment. If implements , a created instance will get disposed when Container.Dispose gets called. The concrete type that will be registered. Thrown when this container instance is locked and can not be altered, or when has already been registered. Thrown when the is a type that can not be created by the container. Registers that the same a single instance of type will be returned every time an type is requested. If and represent the same type, the type is registered by itself. must be thread-safe when working in a multi-threaded environment. If implements , a created instance will get disposed when Container.Dispose gets called. The interface or base type that can be used to retrieve the instances. The concrete type that will be registered. Thrown when this container instance is locked and can not be altered, or when the has already been registered. Thrown when the given type is not a type that can be created by the container. Registers the specified delegate that allows constructing a single instance of . 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 implements , the created instance will get disposed when Container.Dispose gets called. The interface or base type that can be used to retrieve instances. The delegate that allows building or creating this single instance. Thrown when this container instance is locked and can not be altered, or when a for has already been registered. Thrown when is a null reference. Registers that the same instance of type will be returned every time an instance of type type is requested. If and represent the same type, the type is registered by itself. must be thread-safe when working in a multi-threaded environment. Open and closed generic types are supported. The base type or interface to register. This can be an open-generic type. The actual type that will be returned when requested. This can be an open-generic type. Thrown when either or are null references (Nothing in VB). Thrown when is no sub type from , or when one of them represents an open generic type. Thrown when this container instance is locked and can not be altered, or when an the has already been registered. Registers the specified delegate that allows constructing a single instance. The container will call this delegate at most once during the lifetime of the application. The base type or interface to register. The delegate that will be used for creating that single instance. Thrown when represents an open generic type. Thrown when either or are null references (Nothing in VB). Thrown when this container instance is locked and can not be altered, or when an the has already been registered. Registers an delegate that runs after the creation of instances that implement or derive from the given . Please note that only instances that are created by the container (using constructor injection) can be initialized this way. The type for which the initializer will be registered. The delegate that will be called after the instance has been constructed and before it is returned. Thrown when the is a null reference. Thrown when this container instance is locked and can not be altered. Multiple delegates can be registered per and multiple initializers can be applied on a created instance, before it is returned. For instance, when registering a for type , the delegate will be called for every instance created by the container, which can be nice for debugging purposes. Note: Initializers are guaranteed to be executed in the order they are registered. The following example shows the usage of the RegisterInitializer method: (); // Configuring property injection for types that implement ICommand: container.RegisterInitializer(command => { command.SendAsync = true; }); // Configuring property injection for types that implement CommandBase: container.RegisterInitializer(command => { command.Clock = container.GetInstance(); }); // Act var command = (ConcreteCommand)container.GetInstance(); // Assert // Because ConcreteCommand implements both ICommand and CommandBase, // both the initializers will have been executed. Assert.IsTrue(command.SendAsync); Assert.IsNotNull(command.Clock); } ]]> The container does not use the type information of the requested service type, but it uses the type information of the actual implementation to find all initialized that apply for that type. This makes it possible to have multiple initializers to be applied on a single returned instance while keeping performance high. Registered initializers will only be applied to instances that are created by the container self (using constructor injection). Types that are newed up manually by supplying a delegate to the container (using the method) or registered as single instance (using ) will not trigger initialization. When initialization of these instances is needed, this must be done manually, as can be seen in the following example: commandInitializer = command => { initializerCallCount++; }); // Configuring that initializer. container.RegisterInitializer(commandInitializer); container.Register(() => { // Create a ConcreteCommand manually: will not be initialized. var command = new ConcreteCommand("Data Source=.;Initial Catalog=db;"); // Run the initializer manually. commandInitializer(command); return command; }); // Act var command = container.GetInstance(); // Assert // The initializer will only be called once. Assert.AreEqual(1, initializerCallCount); } ]]> The previous example shows how a manually created instance can still be initialized. Try to prevent creating types manually, by changing the design of those classes. If possible, create a single public constructor that only contains dependencies that can be resolved. Registers an delegate that runs after the creation of instances for which the supplied returns true. Please note that only instances that are created by the container can be initialized this way. The delegate that will be called after the instance has been constructed and before it is returned. The predicate that will be used to check whether the given delegate must be applied to a registration or not. The given predicate will be called once for each registration in the container. Thrown when either the or are null references. Thrown when this container instance is locked and can not be altered. Note: Initializers are guaranteed to be executed in the order they are registered. Note: The is not guaranteed to be called once per registration; when a registration's instance is requested for the first time simultaneously over multiple thread, the predicate might be called multiple times. The caller of this method is responsible of supplying a predicate that is thread-safe. Adds the for the supplied . This method can be used to apply the same to multiple different service types. The base type or interface to register. The registration that should be stored for the given . Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when is ambiguous, when it is not assignable from the 's ImplementationType or when the supplied is created for a different instance. Thrown when this container instance is locked and can not be altered, or when an the has already been registered. Adds the for the supplied . This method can be used to apply the same to multiple different service types. The base type or interface to register. The registration that should be stored for the given . (container); container.AddRegistration(typeof(IFoo), registration); container.AddRegistration(typeof(IBar), registration); // Act IFoo foo = container.GetInstance(); IBar bar = container.GetInstance(); // Assert bool fooAndBareAreTheSameInstance = object.ReferenceEquals(foo, bar); Assert.IsTrue(fooAndBareAreTheSameInstance); } ]]> In the example above a singleton registration is created for type FooBar and this registration is added to the container for each interface (IFoo and IBar) that it implements. Since both services use the same singleton registration, requesting those services will result in the return of the same (singleton) instance. events are applied to the of the instance and are therefore applied once. events on the other hand get applied to the Expression of the . Since each AddRegistration gets its own instance producer (that wraps the Registration instance), this means that the ExpressionBuilt events will be applied for each registered service type. The most practical example of this is the use of decorators using one of the RegisterDecorator overloads (decorator registration use the ExpressionBuilt event under the covers). Take a look at the following example: (container); container.AddRegistration(typeof(IFoo), registration); container.AddRegistration(typeof(IBar), registration); // Registere a decorator for IBar, but not for IFoo container.RegisterDecorator(typeof(IBar), typeof(BarDecorator)); // Act var foo = container.GetInstance(); var decorator = container.GetInstance() as BarDecorator; var bar = decorator.DecoratedBar; // Assert bool fooAndBareAreTheSameInstance = object.ReferenceEquals(foo, bar); Assert.IsTrue(fooAndBareAreTheSameInstance); } ]]> The example shows that the decorator gets applied to IBar but not to IFoo, but that the decorated IBar is still the same instance as the resolved IFoo instance. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when is not a reference type, is open generic, is ambiguous, when it is not assignable from the 's ImplementationType or when the supplied is created for a different instance. Thrown when this container instance is locked and can not be altered, or when an the has already been registered. Ensures that the supplied decorator is returned, wrapping the original registered , by injecting that service type into the constructor of the supplied . Multiple decorators may be applied to the same . By default, a new instance will be returned on each request (according the Transient lifestyle), independently of the lifestyle of the wrapped service. This method uses the container's LifestyleSelectionBehavior to select the exact lifestyle for the specified type. By default this will be Transient. The RegisterDecorator method works by hooking onto the container's ExpressionBuilt event. This event fires after the ResolveUnregisteredType event, which allows decoration of types that are resolved using unregistered type resolution. Multiple decorators can be applied to the same service type. The order in which they are registered is the order they get applied in. This means that the decorator that gets registered first, gets applied first, which means that the next registered decorator, will wrap the first decorator, which wraps the original service type. Constructor injection will be used on that type, and although it may have many constructor arguments, it must have exactly one argument of the type of , or an argument of type where TResult is . An exception will be thrown when this is not the case. The registered may have a constructor with an argument of type where T is . In this case, an decorated instance will not injected into the , but it will inject a that allows creating instances of the decorated type, according to the lifestyle of that type. This enables more advanced scenarios, such as executing the decorated types on a different thread, or executing decorated instance within a certain scope (such as a lifetime scope). Please see for an example. The service type that will be wrapped by the given . The decorator type that will be used to wrap the original service type. Thrown when does not have a single public constructor, or when does not contain a constructor that has exactly one argument of type or where T is . Ensures that the supplied decorator is returned and cached with the given , wrapping the original registered , by injecting that service type into the constructor of the supplied . Multiple decorators may be applied to the same . Decorators can be applied to both open, closed, and non-generic service types. The RegisterDecorator method works by hooking onto the container's ExpressionBuilt event. This event fires after the ResolveUnregisteredType event, which allows decoration of types that are resolved using unregistered type resolution. Multiple decorators can be applied to the same service type. The order in which they are registered is the order they get registered. This means that the decorator that gets registered first, gets applied first, which means that the next registered decorator, will wrap the first decorator, which wraps the original service type. Constructor injection will be used on that type, and although it may have many constructor arguments, it must have exactly one argument of the type of , or an argument of type where TResult is . An exception will be thrown when this is not the case. The registered may have a constructor with an argument of type where T is . In this case, the will not inject the decorated itself into the instance, but it will inject a that allows creating instances of the decorated type, according to the lifestyle of that type. This enables more advanced scenarios, such as executing the decorated types on a different thread, or executing decorated instance within a certain scope (such as a lifetime scope). Please see for an example. The service type that will be wrapped by the given . The decorator type that will be used to wrap the original service type. The lifestyle that specifies how the returned decorator will be cached. Thrown when one of the arguments is a null reference. Thrown when does not have a single public constructor, or when does not contain a constructor that has exactly one argument of type or where T is . Ensures that the supplied decorator is returned, wrapping the original registered , by injecting that service type into the constructor of the supplied . Multiple decorators may be applied to the same . Decorators can be applied to both open, closed, and non-generic service types. By default, a new instance will be returned on each request (according the Transient lifestyle), independently of the lifestyle of the wrapped service. This method uses the container's LifestyleSelectionBehavior to select the exact lifestyle for the specified type. By default this will be Transient. The RegisterDecorator method works by hooking onto the container's ExpressionBuilt event. This event fires after the ResolveUnregisteredType event, which allows decoration of types that are resolved using unregistered type resolution. Multiple decorators can be applied to the same service type. The order in which they are registered is the order they get applied in. This means that the decorator that gets registered first, gets applied first, which means that the next registered decorator, will wrap the first decorator, which wraps the original service type. Constructor injection will be used on that type, and although it may have many constructor arguments, it must have exactly one argument of the type of , or an argument of type where TResult is . An exception will be thrown when this is not the case. The registered may have a constructor with an argument of type where T is . In this case, an decorated instance will not injected into the , but it will inject a that allows creating instances of the decorated type, according to the lifestyle of that type. This enables more advanced scenarios, such as executing the decorated types on a different thread, or executing decorated instance within a certain scope (such as a lifetime scope). The following example shows the definition of a generic ICommandHandler<T> interface, a CustomerMovedCommandHandler implementing that interface, and a ValidatorCommandHandlerDecorator<T> that acts as a decorator for that interface. { void Handle(TCommand command); } public class CustomerMovedCommand { [Required] public int CustomerId { get; set; } [Required] public Address Address { get; set; } } public class CustomerMovedCommandHandler : ICommandHandler { public void Handle(CustomerMovedCommand command) { // some logic } } // Decorator that validates commands before they get executed. public class ValidatorCommandHandlerDecorator : ICommandHandler { private readonly ICommandHandler decoratedHandler; private readonly Container container; public ValidatorCommandHandlerDecorator( ICommandHandler decoratedHandler, Container container) { this.decoratedHandler = decoratedHandler; this.container = container; } public void Handle(TCommand command) { this.Validate(command); this.decoratedHandler.Handle(command); } private void Validate(TCommand command) { var validationContext = new ValidationContext(command, this.container, null); Validator.ValidateObject(command, validationContext); } } // Decorator that measures the time it takes to execute a command. public class MonitoringCommandHandlerDecorator : ICommandHandler { private readonly ICommandHandler decoratedHandler; private readonly ILogger logger; public MonitoringCommandHandlerDecorator( ICommandHandler decoratedHandler, ILogger logger) { this.decoratedHandler = decoratedHandler; this.logger = logger; } public void Handle(TCommand command) { var watch = Stopwatch.StartNew(); this.decoratedHandler.Handle(command); this.logger.Log(string.Format("{0} executed in {1} ms.", command.GetType().Name, watch.ElapsedMilliseconds)); } } [TestMethod] public static void TestRegisterOpenGenericDecorator() { // Arrange var container = new Container(); container.Register(Lifestyle.Singleton); // Search the given assembly and register all concrete types that // implement ICommandHandler. container.RegisterManyForOpenGeneric(typeof(ICommandHandler<>), typeof(ICommandHandler<>).Assembly); // Wrap all ICommandHandler service types with a decorator // that measures and logs the duration of that handler. container.RegisterDecorator(typeof(ICommandHandler<>), typeof(MonitoringCommandHandlerDecorator<>)); // Wrap all ICommandHandler types (in this case it will // wrap the monitoring decorator), but only if the TCommand contains // any properties. container.RegisterDecorator(typeof(ICommandHandler<>), typeof(ValidatorCommandHandlerDecorator<>), context => { var commandType = context.ServiceType.GetGenericArguments()[0]; bool mustDecorate = commandType.GetProperties().Any(); return mustDecorate; }); // Act var handler = container.GetInstance>(); // Assert Assert.IsInstanceOfType(handler, typeof(ValidatorCommandHandlerDecorator)); } ]]> The (possibly open generic) service type that will be wrapped by the given . The (possibly the open generic) decorator type that will be used to wrap the original service type. Thrown when one of the arguments is a null reference. Thrown when is not an open generic type, when does not inherit from or implement , when does not have a single public constructor, or when does not contain a constructor that has exactly one argument of type or where T is . Ensures that the supplied decorator is returned and cached with the given , wrapping the original registered , by injecting that service type into the constructor of the supplied . Multiple decorators may be applied to the same . Decorators can be applied to both open, closed, and non-generic service types. The RegisterDecorator method works by hooking onto the container's ExpressionBuilt event. This event fires after the ResolveUnregisteredType event, which allows decoration of types that are resolved using unregistered type resolution. Multiple decorators can be applied to the same service type. The order in which they are registered is the order they get registered. This means that the decorator that gets registered first, gets applied first, which means that the next registered decorator, will wrap the first decorator, which wraps the original service type. Constructor injection will be used on that type, and although it may have many constructor arguments, it must have exactly one argument of the type of , or an argument of type where TResult is . An exception will be thrown when this is not the case. The registered may have a constructor with an argument of type where T is . In this case, the will not inject the decorated itself into the instance, but it will inject a that allows creating instances of the decorated type, according to the lifestyle of that type. This enables more advanced scenarios, such as executing the decorated types on a different thread, or executing decorated instance within a certain scope (such as a lifetime scope). Please see the RegisterDecorator method for more information. The definition of the (possibly open generic) service type that will be wrapped by the given . The definition of the (possibly open generic) decorator type that will be used to wrap the original service type. The lifestyle that specifies how the returned decorator will be cached. Thrown when one of the arguments is a null reference. Thrown when is not an open generic type, when does not inherit from or implement , when does not have a single public constructor, or when does not contain a constructor that has exactly one argument of type or where T is . Ensures that the supplied decorator is returned when the supplied returns true and cached with the given , wrapping the original registered , by injecting that service type into the constructor of the supplied . Multiple decorators may be applied to the same . Decorators can be applied to both open, closed, and non-generic service types. The RegisterDecorator method works by hooking onto the container's ExpressionBuilt event. This event fires after the ResolveUnregisteredType event, which allows decoration of types that are resolved using unregistered type resolution. Multiple decorators can be applied to the same service type. The order in which they are registered is the order they get applied in. This means that the decorator that gets registered first, gets applied first, which means that the next registered decorator, will wrap the first decorator, which wraps the original service type. Constructor injection will be used on that type, and although it may have many constructor arguments, it must have exactly one argument of the type of , or an argument of type where TResult is . An exception will be thrown when this is not the case. The registered may have a constructor with an argument of type where T is . In this case, the will not inject the decorated itself into the instance, but it will inject a that allows creating instances of the decorated type, according to the lifestyle of that type. This enables more advanced scenarios, such as executing the decorated types on a different thread, or executing decorated instance within a certain scope (such as a lifetime scope). Please see the RegisterDecorator method for more information. The definition of the (possibly open generic) service type that will be wrapped by the given . The definition of the (possibly open generic) decorator type that will be used to wrap the original service type. The lifestyle that specifies how the returned decorator will be cached. The predicate that determines whether the must be applied to a service type. Thrown when one of the arguments is a null reference. Thrown when is not an open generic type, when does not inherit from or implement , when does not have a single public constructor, or when does not contain a constructor that has exactly one argument of type or where T is . Ensures that the decorator type that is returned from is supplied when the supplied returns true and cached with the given , wrapping the original registered , by injecting that service type into the constructor of the decorator type that is returned by the supplied . Multiple decorators may be applied to the same . Decorators can be applied to both open, closed, and non-generic service types. The types returned from the may be non-generic, closed-generic, open-generic and even partially-closed generic. The container will try to fill in the generic parameters based on the resolved service type. The RegisterDecorator method works by hooking onto the container's ExpressionBuilt event. This event fires after the ResolveUnregisteredType event, which allows decoration of types that are resolved using unregistered type resolution. Multiple decorators can be applied to the same service type. The order in which they are registered is the order they get applied in. This means that the decorator that gets registered first, gets applied first, which means that the next registered decorator, will wrap the first decorator, which wraps the original service type. Constructor injection will be used on that type, and although it may have many constructor arguments, it must have exactly one argument of the type of , or an argument of type where TResult is . An exception will be thrown when this is not the case. The type returned from may have a constructor with an argument of type where T is . In this case, the library will not inject the decorated itself into the decorator instance, but it will inject a that allows creating instances of the decorated type, according to the lifestyle of that type. This enables more advanced scenarios, such as executing the decorated types on a different thread, or executing decorated instance within a certain scope (such as a lifetime scope). The following is an example of the registration of a decorator through the factory delegate: , MoveCustomerCommandHandler>(); container.RegisterDecorator( typeof(ICommandHandler<>), context => typeof(LoggingCommandHandler<,>).MakeGenericType( typeof(LoggingCommandHandler<,>).GetGenericArguments().First(), context.ImplementationType), Lifestyle.Transient, context => true); var handler = container.GetInstance>(); Assert.IsInstanceOfType(handler, typeof(LoggingCommandHandler)); ]]> The code above allows a generic LoggingCommandHandler<TCommand, TImplementation> to be applied to command handlers, where the second generic argument will be filled in using the contextual information. The definition of the (possibly open generic) service type that will be wrapped by the decorator type that is returned from . A factory that allows building Type objects that define the decorators to inject, based on the given contextual information. The delegate is allowed to return (partially) open-generic types. The lifestyle that specifies how the returned decorator will be cached. The predicate that determines whether the decorator must be applied to a service type. Thrown when one of the arguments is a null reference. Ensures that the supplied decorator is returned when the supplied returns true, wrapping the original registered , by injecting that service type into the constructor of the supplied . Multiple decorators may be applied to the same . Decorators can be applied to both open, closed, and non-generic service types. By default, a new instance will be returned on each request (according the Transient lifestyle), independently of the lifestyle of the wrapped service. This method uses the container's LifestyleSelectionBehavior to select the exact lifestyle for the specified type. By default this will be Transient. The RegisterDecorator method works by hooking onto the container's ExpressionBuilt event. This event fires after the ResolveUnregisteredType event, which allows decoration of types that are resolved using unregistered type resolution. Multiple decorators can be applied to the same service type. The order in which they are registered is the order they get applied in. This means that the decorator that gets registered first, gets applied first, which means that the next registered decorator, will wrap the first decorator, which wraps the original service type. Constructor injection will be used on that type, and although it may have many constructor arguments, it must have exactly one argument of the type of , or an argument of type where TResult is . An exception will be thrown when this is not the case. The registered may have a constructor with an argument of type where T is . In this case, the will not inject the decorated itself into the instance, but it will inject a that allows creating instances of the decorated type, according to the lifestyle of that type. This enables more advanced scenarios, such as executing the decorated types on a different thread, or executing decorated instance within a certain scope (such as a lifetime scope). Please see the RegisterDecorator method for more information. The definition of the (possibly open generic) service type that will be wrapped by the given . The definition of the (possibly open generic) decorator type that will be used to wrap the original service type. The predicate that determines whether the must be applied to a service type. Thrown when one of the arguments is a null reference. Thrown when does not inherit from or implement , when does not have a single public constructor, or when does not contain a constructor that has exactly one argument of type or where T is . Gets an instance of the given . Type of object requested. The requested service instance. Thrown when there are errors resolving the service instance. Gets an instance of the given . Type of object requested. The requested service instance. Thrown when there are errors resolving the service instance. Gets all instances of the given currently registered in the container. Type of object requested. A sequence of instances of the requested TService. Thrown when there are errors resolving the service instance. Gets all instances of the given currently registered in the container. Type of object requested. A sequence of instances of the requested serviceType. Thrown when there are errors resolving the service instance. Gets the service object of the specified type. An object that specifies the type of service object to get. A service object of type serviceType. -or- null if there is no service object of type . Gets the for the given . 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 event registered that acts on that type, or when the service type is an . Otherwise null (Nothing in VB) is returned. A call to this method locks the container. New registrations can't be made after a call to this method. Note: This method is not guaranteed to always return the same instance for a given . It will however either always return null or always return a producer that is able to return the expected instance. The that the returned instance producer should produce. An or null (Nothing in VB). Gets the for the given . 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 event registered that acts on that type, or when the service type is an . Otherwise null (Nothing in VB) is returned, or an exception is throw when is set to true. A call to this method locks the container. New registrations can't be made after a call to this method. Note: This method is not guaranteed to always return the same instance for a given . It will however either always return null or always return a producer that is able to return the expected instance. The that the returned instance producer should produce. The indication whether the method should return null or throw an exception when the type is not registered. An or null (Nothing in VB). 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. Thrown when the registration of instances was invalid. Verifies the Container. This method will call all registered delegates, iterate registered collections and throws an exception if there was an error. Specifies how the container should verify its configuration. Thrown when the registration of instances was invalid. Thrown in case there are diagnostic errors and the option is supplied. Thrown when has an invalid value. Contains methods for registering and creating collections in the . Gets the for this instance. The for this instance. Creates a collection of all concrete, non-generic types (both public and internal) that are defined in the given set of and that implement the given with a default lifestyle and register them as a collection of . Unless overridden using a custom LifestyleSelectionBehavior, the default lifestyle is Transient. The element type of the collections to register. A list of assemblies that will be searched. Thrown when one of the supplied arguments contain a null reference (Nothing in VB). A collection that acts as stream, and calls back into the container to resolve instances every time the collection is enumerated. Creates a collection of all concrete, non-generic types (both public and internal) that are defined in the given set of and that implement the given with a default lifestyle and register them as a collection of . Unless overridden using a custom LifestyleSelectionBehavior, the default lifestyle is Transient. The element type of the collections to register. A list of assemblies that will be searched. Thrown when one of the supplied arguments contain a null reference (Nothing in VB). A collection that acts as stream, and calls back into the container to resolve instances every time the collection is enumerated. Creates a collection of , whose instances will be resolved lazily each time the returned collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. A collection that acts as stream, and calls back into the container to resolve instances every time the collection is enumerated. Thrown when is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element, a generic type definition, or the is not assignable from one of the given elements. Creates a collection of , whose instances will be resolved lazily each time the returned collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. A collection that acts as stream, and calls back into the container to resolve instances every time the collection is enumerated. Thrown when is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element, a generic type definition, or the is not assignable from one of the given elements. Creates a collection of , whose instances will be resolved lazily each time the returned collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. A collection that acts as stream, and calls back into the container to resolve instances every time the collection is enumerated. Thrown when is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element or when is not assignable from any of the types supplied by the given instances. Creates a collection of , whose instances will be resolved lazily each time the returned collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. A collection that acts as stream, and calls back into the container to resolve instances every time the collection is enumerated. Thrown when is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element or when is not assignable from any of the types supplied by the given instances. Creates a new instance defining the creation of a collection of all concrete, non-generic types (both public and internal) that are defined in the given set of and that implement the given with a default lifestyle and register them as a collection of . Unless overridden using a custom LifestyleSelectionBehavior, the default lifestyle is Transient. The collection's instances will be resolved lazily each time the returned collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. A list of assemblies that will be searched. A new instance. Thrown when one of the supplied arguments contain a null reference (Nothing in VB). Creates a new instance defining the creation of a collection of all concrete, non-generic types (both public and internal) that are defined in the given set of and that implement the given with a default lifestyle and register them as a collection of . Unless overridden using a custom LifestyleSelectionBehavior, the default lifestyle is Transient. The collection's instances will be resolved lazily each time the returned collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. A list of assemblies that will be searched. A new instance. Thrown when one of the supplied arguments contain a null reference (Nothing in VB). Creates a new instance defining the creation of a collection of , whose instances will be resolved lazily each time the returned collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. A new instance. Thrown when is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element, a generic type definition, or the is not assignable from one of the given elements. Creates a new instance defining the creation of a collection of , whose instances will be resolved lazily each time the returned collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. A new instance. Thrown when is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element, a generic type definition, or the is not assignable from one of the given elements. Creates a new instance defining the creation of a collection of , whose instances will be resolved lazily each time the returned collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. A new instance. Thrown when is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element or when is not assignable from any of the types supplied by the given instances. Creates a new instance defining the creation of a collection of , whose instances will be resolved lazily each time the returned collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. A new instance. Thrown when is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element or when is not assignable from any of the types supplied by the given instances. Allows appending new registrations to existing registrations made using one of the Collections.Register overloads. The service type of the collection. The registration to append. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when the is not a reference type, is open generic, or ambiguous. Thrown when the container is locked. Thrown when the method is called for a registration that is made with one of the Collections.Register overloads that accepts a dynamic collection (an IEnumerable or IEnumerable<TService>). Allows appending new registrations to existing registrations made using one of the Collections.Register overloads. The service type of the collection. The implementation type to append. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when the is not a reference type, or ambiguous. Thrown when the container is locked. Thrown when the method is called for a registration that is made with one of the Collections.Register overloads that accepts a dynamic collection (an IEnumerable or IEnumerable<TService>). Appends a new to a collection of registrations for the given . Calls to Append can both preceed and follow a call to one of the Container.Collections.Register overloads. The service type of the collection. The registration to append. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when the is not a reference type, is open generic, or ambiguous. Thrown when the container is locked. Thrown when the method is called for a registration that is made with one of the Collections.Register overloads that accepts a dynamic collection (an IEnumerable or IEnumerable<TService>). Appends a new registration of to a collection of registrations for the given . Calls to Append can both preceed and follow a call to one of the Container.Collections.Register overloads. The element type of the collections to register. The concrete type that will be appended as registration to the collection. Thrown when the is ambiguous. Appends a new registration of to a collection of registrations for the given using the supplied . Calls to Append can both preceed and follow a call to one of the Container.Collections.Register overloads. The element type of the collections to register. The concrete type that will be appended as registration to the collection. The lifestyle that specifies how the returned instance will be cached. Thrown when the is ambiguous. Thrown when is a null reference. Appends a new registration of to a collection of registrations for the given . Calls to Append can both preceed and follow a call to one of the Container.Collections.Register overloads. The service type of the collection. The implementation type to append. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when the is not a reference type, or ambiguous. Thrown when the container is locked. Thrown when the method is called for a registration that is made with one of the Collections.Register overloads that accepts a dynamic collection (an IEnumerable or IEnumerable<TService>). Appends a new registration of to a collection of registrations for the given using the supplied . Calls to Append can both preceed and follow a call to one of the Container.Collections.Register overloads. The service type of the collection. The implementation type to append. The lifestyle that specifies how the returned instance will be cached. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when the is not a reference type, or ambiguous. Thrown when the container is locked. Thrown when the method is called for a registration that is made with one of the Collections.Register overloads that accepts a dynamic collection (an IEnumerable or IEnumerable<TService>). Appends the specified delegate to a collection of registrations for the given using the supplied . Calls to Append can both preceed and follow a call to one of the Container.Collections.Register overloads. The element type of the collections to register. The delegate that allows building or creating new instances. The lifestyle that specifies how the returned instance will be cached. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when the is not a reference type, or ambiguous. Thrown when the container is locked. Thrown when the method is called for a registration that is made with one of the Collections.Register overloads that accepts a dynamic collection (an IEnumerable or IEnumerable<TService>). Appends a single instance to a collection of registrations for the given . Calls to AppendInstance can both preceed and follow a call to one of the Container.Collections.Register overloads. This 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; the instance is assumed to outlive this container instance. If disposing is required, use RegisterSingleton<TService>(Func<TService>). The element type of the collections to register. The instance to register. Thrown when the is ambiguous. Thrown when is a null reference. Appends a single instance to a collection of registrations for the given . Calls to AppendInstance can both preceed and follow a call to one of the Container.Collections.Register overloads. This 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; the instance is assumed to outlive this container instance. If disposing is required, use RegisterSingleton<TService>(Func<TService>). TThe element type of the collections to register. The instance to register. Thrown when the is ambiguous, or does not implement . Thrown when either or are null references. Registers a dynamic (container uncontrolled) collection of elements of type . A call to will return the 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. The interface or base type that can be used to retrieve instances. The container-uncontrolled collection to register. Thrown when this container instance is locked and can not be altered, or when a for has already been registered. Thrown when is a null reference. Registers a collection of singleton elements of type . The interface or base type that can be used to retrieve instances. The collection to register. Thrown when this container instance is locked and can not be altered, or when a for has already been registered. Thrown when is a null reference. Thrown when one of the elements of is a null reference. Registers a collection of , whose instances will be resolved lazily each time the resolved collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. Thrown when is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element, a generic type definition, or the is not assignable from one of the given elements. Registers a collection of , whose instances will be resolved lazily each time the resolved collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. Thrown when is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element, a generic type definition, or the is not assignable from one of the given elements. Registers a collection of , whose instances will be resolved lazily each time the resolved collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element or when is not assignable from any of the service types supplied by the given instances. Registers a collection of , whose instances will be resolved lazily each time the resolved collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. The collection of objects whose instances will be requested from the container. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element, a generic type definition, or the is not assignable from one of the given elements. Registers a collection of , whose instances will be resolved lazily each time the resolved collection of is enumerated. The underlying collection is a stream that will return individual instances based on their specific registered lifestyle, for each call to . 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. The base type or interface for elements in the collection. This can be an a non-generic type, closed generic type or generic type definition. The collection of objects whose instances will be requested from the container. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when contains a null (Nothing in VB) element or when is not assignable from any of the service types supplied by the given instances. Registers a dynamic (container uncontrolled) collection of elements of type . A call to will return the 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. The base type or interface for elements in the collection. The collection of items to register. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Thrown when represents an open generic type. Registers all concrete, non-generic types (both public and internal) that are defined in the given set of and that implement the given with a default lifestyle and register them as a collection of . Unless overridden using a custom LifestyleSelectionBehavior, the default lifestyle is Transient. The element type of the collections to register. This can be either a non-generic, closed-generic or open-generic type. A list of assemblies that will be searched. Thrown when one of the supplied arguments contain a null reference (Nothing in VB). Registers all concrete, non-generic types (both public and internal) that are defined in the given set of and that implement the given with a default lifestyle and register them as a collection of . Unless overridden using a custom LifestyleSelectionBehavior, the default lifestyle is Transient. The element type of the collections to register. This can be either a non-generic, closed-generic or open-generic type. A list of assemblies that will be searched. Thrown when one of the supplied arguments contain a null reference (Nothing in VB). Registers all concrete, non-generic types (both public and internal) that are defined in the given set of and that implement the given with a default lifestyle and register them as a collection of . Unless overridden using a custom LifestyleSelectionBehavior, the default lifestyle is Transient. Composites, decorators and generic type definitions will be excluded from registration. The element type of the collections to register. This can be either a non-generic, closed-generic or open-generic type. A list of assemblies that will be searched. Thrown when one of the supplied arguments contain a null reference (Nothing in VB). Registers all concrete, non-generic types (both public and internal) that are defined in the given set of and that implement the given with a default lifestyle and register them as a collection of . Unless overridden using a custom LifestyleSelectionBehavior, the default lifestyle is Transient. Composites, decorators and generic type definitions will be excluded from registration. The element type of the collections to register. This can be either a non-generic, closed-generic or open-generic type. A list of assemblies that will be searched. Thrown when one of the supplied arguments contain a null reference (Nothing in VB). Provides data for and interaction with the ContainerLocking event of the . Delegate that allows intercepting calls to and . Contextual information about the to be created object. A delegate that produces the actual instance according to its lifestyle settings. The instance that is returned from or an intercepted instance. Configuration options for the Container. The following example shows the typical usage of the ContainerOptions class. (); // Use of ContainerOptions class here. container.Options.AllowOverridingRegistrations = true; // Replaces the previous registration of ITimeProvider container.Register(); ]]> 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 ContainerLocking event is called exactly once by the container, allowing a developer to register types, hook unregistered type resolution events that need to be applied last, or see who is responsible for locking the container. A registered event handler delegate is allowed to make a call that locks the container, e.g. calling Container.GetInstance; this will not cause any new ContainerLocking event to be raised. Doing so, however, is not advised, as that might cause any following executed handlers to break, in case they require an unlocked container. Gets the container to which this ContainerOptions instance belongs to. The current Container. Gets or sets a value indicating whether the container allows overriding registrations. The default is false. The value indicating whether the container allows overriding registrations. Gets or sets a value indicating whether the container should suppress checking for lifestyle mismatches (see: https://simpleinjector.org/dialm) when a component is resolved. The default is false. This setting will have no effect when is true. The value indicating whether the container should suppress checking for lifestyle mismatches. 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. The value indicating whether the container should automatically trigger verification. Gets or sets a value indicating whether. This method is deprecated. Changing its value will have no effect. The value indicating whether the container will return an empty collection. 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. The value indicating whether exception message should emit full type names. Gets or sets a value indicating whether the container should resolve unregistered concrete types. The default value is true. Consider changing the value to false to prevent accidental creation of types you haven't registered explicitly. The value indicating whether the container should resolve unregistered concrete types. Thrown when this container instance is locked and can not be altered. Gets or sets the constructor resolution behavior. By default, the container only supports types that have a single public constructor. The constructor resolution behavior. Thrown when the supplied value is a null reference. Thrown when the container already contains registrations. Gets or sets the dependency injection behavior. The constructor injection behavior. Thrown when the supplied value is a null reference. Thrown when the container already contains registrations. Gets or sets the property selection behavior. The container's default behavior is to do no property injection. The property selection behavior. Thrown when the supplied value is a null reference. Thrown when the container already contains registrations. Gets or sets the lifestyle selection behavior. The container's default behavior is to make registrations using the lifestyle. The lifestyle selection behavior. Thrown when the supplied value is a null reference. Thrown when the container already contains registrations. Gets or sets the default lifestyle that the container will use when a registration is made when no lifestyle is supplied. The default lifestyle. Thrown when the supplied value is a null reference. Thrown when the container already contains registrations. Gets or sets the default scoped lifestyle that the container should use when a registration is made using Lifestyle.Scoped. The default scoped lifestyle. Thrown when the supplied value is a null reference. Thrown when the container already contains registrations. 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. A boolean indicating whether the container should use a dynamic assembly for compilation. Registers an delegate that allows intercepting calls to GetInstance and . If multiple registered instances must be applied, they will be applied/wrapped in the order of registration, i.e. the first registered interceptor will call the original instance producer delegate, the second interceptor will call the first interceptor, etc. The last registered interceptor will become the outermost method in the chain and will be called first. The delegate to register. The predicate that will be used to check whether the given delegate must be applied to a registration or not. The given predicate will be called once for each registration in the container. Thrown when either the or are null references. Thrown when this container instance is locked and can not be altered. The following example shows the usage of the method: { object instance = producer.Invoke(); Console.WriteLine(instance.GetType().Name + " resolved for " + context.Producer.ServiceType.Name); return instance; }, context => context.Producer.ServiceType.Name.EndsWith("Controller")); container.Register(); container.Register(); // This line will write "HomeViewModel resolved for IHomeViewModel" to the console. container.GetInstance(); ]]> Returns a string that represents the current object. A string that represents the current object. The scope that manages the lifetime of singletons and other container-controlled instances. Allows registering an delegate that will be called when the container gets disposed, but before the container disposes any instances. During the call to all registered delegates are processed in the order of registration. Do note that registered actions are not guaranteed to run. In case an exception is thrown during the call to Dispose, the will stop running any actions that might not have been invoked at that point. Instances that are registered for disposal using on the other hand, are guaranteed to be disposed. Note that registered actions won't be invoked during a call to . The delegate to run when the scope ends. Thrown when one of the arguments is a null reference (Nothing in VB). Thrown when the container has been disposed. Adds the to the list of items that will get disposed when the container gets disposed. Instances that are registered for disposal, will be disposed in opposite order of registration and they are guaranteed to be disposed when is called (even when exceptions are thrown). This mimics the behavior of the C# and VB using statements, where the method is called inside the finally block. The instance that should be disposed when the scope ends. Thrown when one of the arguments is a null reference (Nothing in VB). Thrown when the container has been disposed. Retrieves an item from the scope stored by the given or null when no item is stored by that key. Thread-safety: Calls to this method are thread-safe, but users should take proper percussions when they call both GetItem and . The key of the item to retrieve. The stored item or null (Nothing in VB). Thrown when one of the supplied arguments is a null reference (Nothing in VB). Stores an item by the given in the scope. Thread-safety: Calls to this method are thread-safe, but users should take proper percussions when they call both and SetItem. Instead, provides an atomic operation for getting and setting an item. The key of the item to insert or override. The actual item. May be null. Thrown when paramref name="key"/> is a null reference (Nothing in VB). Adds an item by the given in the container by using the specified function, if the key does not already exist. This operation is atomic. The Type of the item to create. The key of the item to insert or override. The function used to generate a value for the given key. The supplied value of will be supplied to the function when called. The stored item or the item from the . Thrown when either of the arguments is a null reference (Nothing in VB). Returns the list of instances that will be disposed of when this instance is being disposed. The list contains scoped instances that are cached in this instance, and instances explicitly registered for disposal using . The instances are returned in order of creation/registration. When Container.Dispose is called, the scope will ensure is called on each instance in this list. The instance will be disposed in opposite order as they appear in the list. The list of instances that will be disposed of when this instance is being disposed. An instance of this type can be injected into constructors of decorator classes that are registered using RegisterDecorator. This type contains contextual information about the applied decoration and it allows users to examine the given instance to make runtime decisions. Gets the closed generic service type for which the decorator is about to be applied. The original service type will be returned, even if other decorators have already been applied to this type. The closed generic service type. Gets the type of the implementation that is created by the container and for which the decorator is about to be applied. The original implementation type will be returned, even if other decorators have already been applied to this type. Please not that the implementation type can not always be determined. In that case the closed generic service type will be returned. The implementation type. Gets the list of the types of decorators that have already been applied to this instance. The applied decorators. Gets the current object that describes the intention to create a new instance with its currently applied decorators. The current expression that is about to be decorated. An instance of this type will be supplied to the delegate that is that is supplied to the RegisterDecorator overload that takes this delegate. This type contains information about the decoration that is about to be applied and it allows users to examine the given instance to see whether the decorator should be applied or not. Please see the RegisterDecorator method for more information. Gets the closed generic service type for which the decorator is about to be applied. The original service type will be returned, even if other decorators have already been applied to this type. The closed generic service type. Gets the type of the implementation that is created by the container and for which the decorator is about to be applied. The original implementation type will be returned, even if other decorators have already been applied to this type. Please not that the implementation type can not always be determined. In that case the closed generic service type will be returned. The implementation type. Gets the list of the types of decorators that have already been applied to this instance. The applied decorators. Gets the current object that describes the intention to create a new instance with its currently applied decorators. The current expression that is about to be decorated. Hooks into the building process and adds a decorator if needed. Diagnostic result that warns about when a multiple registrations map to the same implementation type and lifestyle, which might cause multiple instances to be created during the lifespan of that lifestyle. For more information, see: https://simpleinjector.org/diaal. Gets the lifestyles that causes the registrations to be conflicting. instances. Gets the implementation type that the affected registrations map to. A . Gets the registration that caused this warning. An . Gets the list of registrations that are in conflict with the . A list of instances. Entry point for doing diagnostic analysis on instances. The following example shows the usage of the Analyzer class: Analyzes the supplied instance. The container instance to analyze. A collection of sub types that describe the diagnostic warnings and messages. Diagnostic result for a warning about a concrete type that was not registered explicitly and was not resolved using unregistered type resolution, but was created by the container using the transient lifestyle. For more information, see: https://simpleinjector.org/diaut. Gets a collection of instances that describe all container-registered dependencies for the given component. List of objects. A hierarchical group of . Gets the base that describes the service types of its . The value often be either (in case this is a root group) or a partial generic type to allow hierarchical grouping of a large number of related generic types. The . Gets the friendly name of the group. The name. Gets the description of the group. The description. Gets the diagnostic type of all grouped instances. The . Gets the parent or null (Nothing in VB) when this is the root group. The . Gets the collection of child s. A collection of elements. Gets the collection of instances. /// A collection of elements. Base class for types that hold information about a single diagnostic message or warning for a particular type or part of the configuration. Gets the severity of this result. The . Gets the diagnostic type of this result. The . Gets the service type to which this warning is related. A . Gets the description of the diagnostic result. A with the description. Gets the documentation URL of the diagnostic result. A with the URL. Gets the hierarchical group to which this diagnostic result belongs. The . Specifies the list of severity levels that diagnostic results can have. Information messages and tips about the configuration. Warning messages that are likely to cause problems in your application. Specifies the list of diagnostic types that are currently supported by the diagnostic . Note that new diagnostic types might be added in future versions. For more information, please read the Diagnosing your configuration using the Diagnostic Services wiki documentation. Diagnostic type that warns about a concrete type that was not registered explicitly and was not resolved using unregistered type resolution, but was created by the container using the transient lifestyle. For more information, see: https://simpleinjector.org/diaut. Diagnostic type that warns when a component depends on a service with a lifestyle that is shorter than that of the component. For more information, see: https://simpleinjector.org/dialm. Diagnostic type that warns when a component depends on an unregistered concrete type and this concrete type has a lifestyle that is different than the lifestyle of an explicitly registered type that uses this concrete type as its implementation. For more information, see: https://simpleinjector.org/diasc. Diagnostic type that warns when a component depends on (too) many services. For more information, see: https://simpleinjector.org/diasr. Diagnostic type that warns when multiple registrations map to the same component and lifestyle, which might cause multiple instances to be created during the lifespan of that lifestyle. For more information, see: https://simpleinjector.org/diatl. Diagnostic type that warns when a component is registered as transient, while implementing . For more information, see: https://simpleinjector.org/diadt. Diagnostic type that warns when multiple registrations exist that map to the same component but with different lifestyles, which will cause the component to be cached in different -possibly incompatible- ways. For more information, see: https://simpleinjector.org/diaal. Diagnostic result for a warning about a component that is registered as transient, but implements . For more information, see: https://simpleinjector.org/diadt. Gets the object that describes the relationship between the component and its dependency. A instance. Diagnostic result for a warning about a component that depends on a service with a lifestyle that is shorter than that of the component. For more information, see: https://simpleinjector.org/dialm. Gets the object that describes the relationship between the component and its dependency. A instance. Diagnostic result that warns about a component that depends on an unregistered concrete type and this concrete type has a lifestyle that is different than the lifestyle of an explicitly registered type that uses this concrete type as its implementation. For more information, see: https://simpleinjector.org/diasc. Gets the instance that describes the current relationship between the checked component and the short-circuited dependency. The . Gets the collection of registrations that have the component's current dependency as implementation type, but have a lifestyle that is different than the current dependency. A collection of instances. Diagnostic result that warns about a component that depends on (too) many services. For more information, see: https://simpleinjector.org/diasr. Gets the created type. A . Gets the list of registrations that are dependencies of the . A collection of instances. Diagnostic result that warns about when a multiple registrations map to the same implementation type and lifestyle, which might cause multiple instances to be created during the lifespan of that lifestyle. For more information, see: https://simpleinjector.org/diatl. Gets the lifestyle on which instances are torn. A . Gets the implementation type that the affected registrations map to. A . Gets the list of registrations that are affected by this warning. A list of instances. Thrown by the container in case of a diagnostic error. Initializes a new instance of the class. Initializes a new instance of the class with a specified error message. The message that describes the error. Initializes a new instance of the class with a specified error message. The list of errors. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. The error message that explains the reason for the exception. The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified. Initializes a new instance of the class with serialized data. The that holds the serialized object data about the exception being thrown. The that contains contextual information about the source or destination. The parameter is null. The class name is null or hresult is zero (0). Gets the list of instances. A list of instances. Provides data for and interaction with the ExpressionBuilding event of the . An observer can change the property to change the component that is currently being built. Gets the registered service type that is currently requested. The registered service type that is currently requested. Gets the type that is known to be returned by the Expression (most often the implementation type used in the Register call). This type will be a derivative of RegisteredServiceType (or or RegisteredServiceType itself). If the Expression is changed, the new expression must also return an instance of type KnownImplementationType or a sub type. This information must be described in the new Expression. A . Gets the lifestyle for the component that is currently being built. The . Gets or sets the currently registered Expression. The current registration. Thrown when the supplied value is a null reference. Gets the collection of currently known relationships. This information is used by the Diagnostics Debug View. Change the contents of this collection to represent the changes made to the Expression property (if any). This allows the Diagnostics Debug View to analyze those new relationships as well. The collection of instances. Provides data for and interaction with the ExpressionBuilt event of the . An observer can change the property to change the component that is currently being built. Initializes a new instance of the class. Type of the registered service. The registered expression. Gets the registered service type that is currently requested. The registered service type that is currently requested. Gets or sets the currently registered Expression. The current registration. Thrown when the supplied value is a null reference. Gets or sets the current lifestyle of the registration. The original lifestyle of the registration. Gets the collection of currently known relationships. This information is used by the Diagnostics Debug View. Change the contents of this collection to represent the changes made to the Expression property (if any). This allows the Diagnostics Debug View to analyze those new relationships as well. The collection of instances. Helper methods for the container. Contains contextual information about the direct consumer for which the given dependency is injected into. Initializes a new instance of the class. The constructor parameter for the created component. Initializes a new instance of the class. The implementation type of the consumer of the component that should be created. The property for the created component. Gets the service type of the consumer of the component that should be created. The closed generic service type. Gets the implementation type of the consumer of the component that should be created. The implementation type. Gets the information about the consumer's target in which the dependency is injected. The target can be either a property or a constructor parameter. The for this context. Discovers the attributes of the code element (a property or parameter) where a dependency will be injected into, and provides access to its meta data. Gets the constructor argument of the consumer of the component where the dependency will be injected into. The property can return null. The or null when the dependency is injected into a property. Gets the property of the consumer of the component where the dependency will be injected into. The property can return null. The or null when the dependency is injected into a constructor argument instead. Gets the name of the target. A string containing the name of the target. Gets the type of the target. A containing the type of the target. Gets the member of the target. This is either the constructor of the parameter, or in case the target is a property, the property itself will be returned. A containing the type of the target. Returns an array of all of the custom attributes defined on either the or the , excluding named attributes, or an empty array if there are no custom attributes. When true, look up the hierarchy chain for the inherited custom attribute. An array of Objects representing custom attributes, or an empty array. The custom attribute type cannot be loaded. There is more than one attribute of type attributeType defined on this member. Returns an array of custom attributes defined on either the or the , identified by type, or an empty array if there are no custom attributes of that type. The type of the custom attributes. When true, look up the hierarchy chain for the inherited custom attribute. An array of Objects representing custom attributes, or an empty array. The custom attribute type cannot be loaded. Thrown when attributeType is null. Indicates whether one or more instance of attributeType is defined on this either the or the . The type of the custom attributes. When true, look up the hierarchy chain for the inherited custom attribute. true if the attributeType is defined on this member; false otherwise. Retrieves a custom attribute of a specified type that is applied to a specified parameter. The parameter to inspect. A custom attribute that matches T, or null if no such attribute is found. Retrieves a custom attribute of a specified type that is applied to a specified parameter, and optionally inspects the ancestors of that parameter. The parameter to inspect.The parameter to inspect. True to inspect the ancestors of element; otherwise, false. A custom attribute that matches T, or null if no such attribute is found. Retrieves a custom attribute of a specified type that is applied to a specified parameter. The type of attribute to search for. A custom attribute that matches attributeType, or null if no such attribute is found. Retrieves a custom attribute of a specified type that is applied to a specified parameter, and optionally inspects the ancestors of that parameter. The type of attribute to search for. True to inspect the ancestors of element; otherwise, false. A custom attribute matching attributeType, or null if no such attribute is found. Retrieves a collection of custom attributes of a specified type that are applied to a specified parameter. The type of attribute to search for. A collection of the custom attributes that are applied to element and that match T, or an empty collection if no such attributes exist. Retrieves a collection of custom attributes of a specified type that are applied to a specified parameter, and optionally inspects the ancestors of that parameter. The type of attribute to search for. True to inspect the ancestors of element; otherwise, false. A collection of the custom attributes that are applied to element and that match T, or an empty collection if no such attributes exist. Produces instances for a given registration. Instances of this type are generally created by the container when calling one of the Register overloads. Instances can be retrieved by calling GetCurrentRegistrations() or GetRegistration(Type, bool). The Register method overloads create InstanceProducer instances internally, but InstanceProducers can be created manually to implement special scenarios. An InstanceProducer wraps instance. The Registration builds an that describes the intend to create the instance according to a certain lifestyle. The InstanceProducer on the other hand transforms this Expression to a delegate and allows the actual instance to be created. A Registration itself can't create any instance. The InsanceProducer allows intercepting created instances by hooking onto the Container.ExpressionBuilt event. The RegisterDecorator methods for instance work by hooking onto the ExpressionBuilt event and allow wrapping the returned instance with a decorator. The following example shows the creation of two different InstanceProducer instances that wrap the same Registration instance. Since the Registration is created using the Singleton lifestyle, both producers will return the same instance. The InstanceProducer for the Interface1 however, will wrap that instance in a (transient) Interface1Decorator. (container); var producer1 = new InstanceProducer(typeof(Interface1), registration); var producer2 = new InstanceProducer(typeof(Interface2), registration); container.RegisterDecorator(typeof(Interface1), typeof(Interface1Decorator)); var instance1 = (Interface1)producer1.GetInstance(); var instance2 = (Interface2)producer2.GetInstance(); Assert.IsInstanceOfType(instance1, typeof(Interface1Decorator)); Assert.IsInstanceOfType(instance2, typeof(ServiceImpl)); Assert.AreSame(((Interface1Decorator)instance1).DecoratedInstance, instance2); ]]> Initializes a new instance of the class. The service type for which this instance is created. The . Gets the for this registration. The returned lifestyle can differ from the lifestyle that is used during the registration. This can happen for instance when the registration is changed by an ExpressionBuilt registration or gets decorated. The for this registration. Gets the service type for which this producer produces instances. A instance. Gets the instance for this instance. The . Creates a new based on the given and where the will be used as-is; no interception (using ExpressionBuilt) such as decorators will be applied. The service type for which this instance is created. The expression that describes the instance to be produced. The instance for this registration. A new that describes the expression. Produces an instance. An instance. Will never return null. When the instance could not be retrieved or is null. Builds an expression that expresses the intent to get an instance by the current producer. A call to this method locks the container. New registrations can't be made after a call to this method. An Expression. Gets the collection of relationships for this instance that the container knows about. This includes relationships between the registered type and its dependencies and relationships between applied decorators and their dependencies. Note that types that are not newed up by the container and properties that are injected inside a custom delegate that is registered using the RegisterInitializer method are unknown to the container and are not returned from this method. Also note that this method will return an empty collection when called before the registered type is requested from the container (or before Verify is called). An array of instances. Builds a string representation of the object graph with the current instance as root of the graph. A string representation of the object graph. Thrown when this method is called before or have been called. These calls can be done directly and explicitly by the user on this instance, indirectly by calling or on an instance that depends on this instance, or by calling Verify on the container. Builds a string representation of the object graph with the current instance as root of the graph. The various visualization options for building a string representation of the object graph. A string representation of the object graph. Thrown when this method is called before or have been called. These calls can be done directly and explicitly by the user on this instance, indirectly by calling or on an instance that depends on this instance, or by calling Verify on the container. Thrown when options is null. Produces instances for a given registration. Instances of this type are generally created by the container when calling one of the Register overloads. Instances can be retrieved by calling or . The service type. Initializes a new instance of the class. The . Produces an instance. An instance. Will never return null. When the instance could not be retrieved or is null. A map containing a generic argument (such as T) and the concrete type (such as Int32) that it represents. Implements equality. Needed for doing LINQ distinct operations. The other to compare to. True or false. Overrides the default hash code. Needed for doing LINQ distinct operations. An 32 bit integer. Container controlled collections can be supplied with both Type objects or direct Registration instances. Gets a message that describes the current exception. T he error message that explains the reason for the exception, or an empty string(""). Allows verifying whether a given type has a direct or indirect dependency on itself. Verifying is done by preventing recursive calls to an InstanceProducer. A CyclicDependencyValidator instance checks a single InstanceProducer and therefore a single service type. Allows retrieving the concrete types of the generic type arguments of that must be used to create a closed generic implementation of a given open generic implementation, based on on the concrete arguments of the given closed base type. Helper class for building closed generic type for a given open generic type and a closed generic base. Result of the GenericTypeBuilder. A open generic type with the concrete arguments that can be used to create a closed generic type. Allows validating an ArgumentMapping. Factory for the creation of a delegate that applies caching to the supplied . A factory for creating new instances. A factory that returns cached instances. Instances returned from the container can be cached. The contains several overloads of the Register method that take a Lifestyle instance as argument to define how returned instances should be cached. The core library contains two lifestyles out of the box. By supplying Lifestyle.Transient, the registered instance is not cached; a new instance is returned every time it is requested or injected. By supplying Lifestyle.Singleton instances can be cached indefinitely; only a single instance of the registered component will be returned by that container instance. Other lifestyles are defined in integration and extension packages. The CreateCustom method allows defining a custom lifestyle and the CreateHybrid method allows creating a lifestyle that mixes multiple other lifestyles. This type is abstract and can be overridden to implement a custom lifestyle. The lifestyle instance that doesn't cache instances. A new instance of the specified component is created every time the registered service is requested or injected. The following example registers the SomeServiceImpl implementation for the ISomeService service type using the Transient lifestyle: (Lifestyle.Transient); ]]> Note that Transient is the default lifestyle, the previous registration can be reduced to the following: (); ]]> The lifestyle that caches components according to the lifetime of the container's configured scoped lifestyle. In case the type of a cached instance implements , the container will ensure its disposal when the active scope gets disposed. The following example registers the RealTimeProvider implementation for the ITimeProvider service type using the Scoped lifestyle: (Lifestyle.Scoped); ]]> The lifestyle that caches components during the lifetime of the instance and guarantees that only a single instance of that component is created for that instance. Since general use is to create a single Container instance for the lifetime of the application / AppDomain, this would mean that only a single instance of that component would exist during the lifetime of the application. In a multi-threaded applications, implementations registered using this lifestyle must be thread-safe. In case the type of a cached instance implements , the container will ensure its disposal when the container gets disposed. The following example registers the RealTimeProvider implementation for the ITimeProvider service type using the Singleton lifestyle: (Lifestyle.Singleton); ]]> Initializes a new instance of the class. The user friendly name of this lifestyle. Thrown when is null (Nothing in VB) or an empty string. Gets the user friendly name of this lifestyle. The user friendly name of this lifestyle. Gets the length of the lifestyle. Implementers must implement this property. The diagnostic services use this value to compare lifestyles with each other to determine lifestyle misconfigurations. The representing the length of this lifestyle. The hybrid lifestyle allows mixing two lifestyles in a single registration. The hybrid will use the in case its GetCurrentScope method returns a scope; otherwise the is used. The hybrid lifestyle will redirect the creation of the instance to the selected lifestyle. By nesting hybrid lifestyles, any number of lifestyles can be mixed. The lifestyle to use when its GetCurrentScope method returns a scope.. The lifestyle to use when the GetCurrentScope method of the argument returns null. A new hybrid lifestyle that wraps the supplied lifestyles. Thrown when one of the supplied arguments is a null reference (Nothing in VB). The following example shows the creation of a HybridLifestyle that mixes an ThreadScopedLifestyle and Transient: (hybridLifestyle); container.Register(hybridLifestyle); ]]> Hybrid lifestyles can be nested: The mixedScopeLifestyle now mixed three lifestyles: Web Request, Thread Scoped and Transient. The hybrid lifestyle allows mixing two lifestyles in a single registration. The hybrid will use the in case its GetCurrentScope method returns a scope; otherwise the is used. The hybrid lifestyle will redirect the creation of the instance to the selected lifestyle. By nesting hybrid lifestyles, any number of lifestyles can be mixed. The lifestyle to use when its GetCurrentScope method returns a scope.. The lifestyle to use when the GetCurrentScope method of the argument returns null. A new hybrid lifestyle that wraps the supplied lifestyles. Thrown when one of the supplied arguments is a null reference (Nothing in VB). The following example shows the creation of a HybridLifestyle that mixes an ThreadScopedLifestyle and Transient: (hybridLifestyle); container.Register(hybridLifestyle); ]]> Hybrid lifestyles can be nested: The mixedScopeLifestyle now mixed three lifestyles: Web Request, Thread Scoped and Transient. The hybrid lifestyle allows mixing two lifestyles in a single registration. Based on the supplied delegate the hybrid lifestyle will redirect the creation of the instance to the correct lifestyle. The result of the delegate will not be cached; it is invoked each time an instance is requested or injected. By nesting hybrid lifestyles, any number of lifestyles can be mixed. The delegate that determines which lifestyle should be used. The will be used if true is returned; the otherwise. This delegate will be called every time an instance needs to be resolved or injected. The lifestyle to use when returns true. The lifestyle to use when returns false. A new hybrid lifestyle that wraps the supplied lifestyles. Thrown when one of the supplied arguments is a null reference (Nothing in VB). The following example shows the creation of a HybridLifestyle that mixes an WebRequestLifestyle and ThreadScopedLifestyle: HttpContext.Current != null, new WebRequestLifestyle(), new ThreadScopedLifestyle()); // The created lifestyle can be reused for many registrations. container.Register(mixedScopeLifestyle); container.Register(mixedScopeLifestyle); ]]> Hybrid lifestyles can be nested: lifestyle.GetCurrentScope(container) != null, lifestyle, Lifestyle.Transient); var mixedScopeLifestyle = Lifestyle.CreateHybrid( () => HttpContext.Current != null, new WebRequestLifestyle(), mixedLifetimeTransientLifestyle); ]]> The mixedScopeLifestyle now mixed three lifestyles: Web Request, Lifetime Scope and Transient. The hybrid lifestyle allows mixing two lifestyles in a single registration. Based on the supplied delegate the hybrid lifestyle will redirect the creation of the instance to the correct lifestyle. The result of the delegate will not be cached; it is invoked each time an instance is requested or injected. By nesting hybrid lifestyles, any number of lifestyles can be mixed. The delegate that determines which lifestyle should be used. The will be used if true is returned; the otherwise. This delegate will be called every time an instance needs to be resolved or injected. The scoped lifestyle to use when returns true. The scoped lifestyle to use when returns false. A new scoped hybrid lifestyle that wraps the supplied lifestyles. Thrown when one of the supplied arguments is a null reference (Nothing in VB). The following example shows the creation of a HybridLifestyle that mixes an WebRequestLifestyle and ThreadScopedLifestyle: HttpContext.Current != null, new WebRequestLifestyle(), new ThreadScopedLifestyle()); // The created lifestyle can be reused for many registrations. container.Register(mixedScopeLifestyle); container.Register(mixedScopeLifestyle); ]]> Creates a custom lifestyle using the supplied delegate. The supplied will be called just once per registered service. The supplied will be called by the framework when the type is resolved for the first time, and the framework will supply the factory with a Func<object> for creating new (transient) instances of that type (that might have been intercepted and initializers might have been applied). It is the job of the to return a Func<object> that applies the proper caching. The Func<object> that is returned by the will be stored for that registration (every registration will store its own Func<object> delegate) and this delegate will be called every time the service is resolved (by calling container.GetInstance<TService> or when that service is injected into another type). The name of the lifestyle to create. The name is used to display the lifestyle in the debugger. A factory delegate that takes a Func<object> delegate that will produce a transient instance and returns a delegate that returns cached instances. A new . Thrown when one of the arguments is a null reference (Nothing in VB). Thrown when is an empty string. The following example shows the creation of a lifestyle that caches registered instances for 10 minutes: { TimeSpan timeout = TimeSpan.FromMinutes(10); var syncRoot = new object(); var expirationTime = DateTime.MinValue; object instance = null; // If the application has multiple registrations using this lifestyle, each registration // will get its own Func delegate (created here) and therefore get its own set // of variables as defined above. return () => { lock (syncRoot) { if (expirationTime < DateTime.UtcNow) { instance = instanceCreator(); expirationTime = DateTime.UtcNow.Add(timeout); } return instance; } }; }); var container = new Container(); // We can reuse the created lifestyle for multiple registrations. container.Register(customLifestyle); container.Register(customLifestyle); ]]> Creates a new instance for the given that will create new instances of specified with the caching as specified by this lifestyle. The interface or base type that can be used to retrieve the instances. The concrete type that will be created. The instance for which a must be created. A new instance. Thrown when is a null reference (Nothing in VB). Creates a new instance for the given that will create new instances of specified caching as specified by this lifestyle. The interface or base type that can be used to retrieve the instances. The concrete type that will be created. The instance for which a must be created. A new instance. Thrown when either or are null references (Nothing in VB). Creates a new instance for the given that will create new instances instance using the supplied with the caching as specified by this lifestyle. The interface or base type that can be used to retrieve the instances. A delegate that will create a new instance of every time it is called. The instance for which a must be created. A new instance. Thrown when either or are null references (Nothing in VB). Creates a new instance for the given that will create new instances of specified with the caching as specified by this lifestyle. The interface or base type that can be used to retrieve the instances. The concrete type that will be registered. The instance for which a must be created. A new instance. Thrown when on of the supplied arguments is a null reference (Nothing in VB). Creates a new instance defining the creation of the specified with the caching as specified by this lifestyle, or returns an already created instance for this container + lifestyle + type combination. The concrete type that will be registered. The instance for which a must be created. A new or cached instance. Thrown when is a null reference (Nothing in VB). This overload has been deprecated. Please call instead. The interface or base type that can be used to retrieve the instances. The concrete type that will be created. The instance for which a must be created. A new instance. Thrown when is a null reference (Nothing in VB). Creates a new instance defining the creation of the specified using the supplied with the caching as specified by this lifestyle. The interface or base type that can be used to retrieve the instances. A delegate that will create a new instance of every time it is called. The instance for which a must be created. A new instance. Thrown when either or are null references (Nothing in VB). Creates a new instance defining the creation of the specified with the caching as specified by this lifestyle, or returns an already created instance for this container + lifestyle + type combination. This method might fail when run in a partial trust sandbox when is an internal type. The concrete type that will be registered. The instance for which a must be created. A new instance. Thrown when on of the supplied arguments is a null reference (Nothing in VB). This overload has been deprecated. Please call instead. The interface or base type that can be used to retrieve the instances. The concrete type that will be registered. The instance for which a must be created. A new instance. Thrown when on of the supplied arguments is a null reference (Nothing in VB). Creates a new instance defining the creation of the specified using the supplied with the caching as specified by this lifestyle. The interface or base type that can be used to retrieve the instances. The delegate that will be responsible for creating new instances. The instance for which a must be created. A new instance. Thrown when on of the supplied arguments is a null reference (Nothing in VB). When overridden in a derived class, creates a new instance defining the creation of the specified with the caching as specified by this lifestyle. The concrete type that will be registered. The instance for which a must be created. A new instance. If you are implementing your own lifestyle, override this method to implement the code necessary to create and return a new . Note that you should always create a new instance. They should never be cached. When overridden in a derived class, creates a new instance defining the creation of the specified using the supplied with the caching as specified by this lifestyle. The interface or base type that can be used to retrieve the instances. A delegate that will create a new instance of every time it is called. The instance for which a must be created. A new instance. If you are implementing your own lifestyle, override this method to implement the code necessary to create and return a new . Note that you should always create a new instance. They should never be cached. Defines a lifestyle that caches instances during the lifetime of an explicitly defined scope using the BeginScope method. An execution context scope flows with the logical execution context. Scopes can be nested and nested scopes will get their own instance. Instances created by this lifestyle can be disposed when the created scope gets disposed. The following example shows the usage of the ExecutionContextScopeLifestyle class: (Lifestyle.Scoped); using (AsyncScopedLifestyle.BeginScope(container)) { var instance1 = container.GetInstance(); // ... } ]]> Initializes a new instance of the class. The created and cached instance will be disposed when the created instance gets disposed and when the created object implements . Begins a new scope for the given . Services, registered using the are cached during the lifetime of that scope. The scope should be disposed explicitly. The container. A new instance. Thrown when the is a null reference. Returns the current for this lifestyle and the given , or null when this method is executed outside the context of a scope. The container instance that is related to the scope to return. A instance or null when there is no scope active in this context. Creates a delegate that upon invocation return the current for this lifestyle and the given , or null when the delegate is executed outside the context of such scope. The container for which the delegate gets created. A delegate. This method never returns null. This lifestyle can be used to implement ambient context-less scoping in Simple Injector. This lifestyle can be set as DefaultScopedLifestyle and later used via Lifestyle.Scoped to register scoped instances, while instances are resolved via Scope.GetInstance. Forwards CreateRegistration calls to the lifestyle that is returned from the registered container.Options.LifestyleSelectionBehavior. Defines a lifestyle that caches instances during the lifetime of an explicitly defined scope using the BeginScope method. A scope is thread-specific, each thread should define its own scope. Scopes can be nested and nested scopes will get their own instance. Instances created by this lifestyle can be disposed when the created scope gets disposed. The following example shows the usage of the ThreadScopedLifestyle class: (Lifestyle.Scoped); using (container.BeginLifetimeScope()) { var instance1 = container.GetInstance(); // This call will return the same instance. var instance2 = container.GetInstance(); Assert.IsTrue(object.ReferenceEquals(instance1, instance2)); // Create a nested scope. using (container.BeginLifetimeScope()) { // A nested scope gets its own instance. var instance3 = container.GetInstance(); Assert.IsFalse(object.ReferenceEquals(instance1, instance3)); // This call will return the same instance. var instance4 = container.GetInstance(); Assert.IsTrue(object.ReferenceEquals(instance3, instance4)); } } ]]> Initializes a new instance of the class. The created and cached instance will be disposed when the created instance gets disposed and when the created object implements . Begins a new scope for the given . Services, registered using the are cached during the lifetime of that scope. The scope should be disposed explicitly. The container. A new instance. Thrown when the is a null reference. Creates a delegate that upon invocation return the current for this lifestyle and the given , or null when the delegate is executed outside the context of such scope. The container for which the delegate gets created. A delegate. This method never returns null. Returns the current for this lifestyle and the given , or null when this method is executed outside the context of a scope. The container instance that is related to the scope to return. A instance or null when there is no scope active in this context. An instance of this type will be supplied to the delegate that is that is supplied to the RegisterConditional overload that takes this delegate. This type contains information about the open generic service that is about to be created and it allows the user to examine the given instance to decide whether this implementation should be created or not. Please see the Register method for more information. Gets the closed generic service type that is to be created. The closed generic service type. Gets the closed generic implementation type that will be created by the container. The implementation type. Gets a value indicating whether a previous Register registration has already been applied for the given . The indication whether the event has been handled. Gets the contextual information of the consuming component that directly depends on the resolved service. This property will return null in case the service is resolved directly from the container. The or null. A Registration implements lifestyle based caching for a single service and allows building an that describes the creation of the service. implementations create a new Registration instance for each registered service type. s returned from the BuildExpression method can be intercepted by any event registered with , have initializers applied, and the caching particular to its lifestyle have been applied. Interception using the Container.ExpressionBuilt will not be applied in the Registration, but will be applied in . See the documentation for an example. Initializes a new instance of the class. The this that created this registration. The instance for this registration. Thrown when one of the supplied arguments is a null reference (Nothing in VB). Gets the type that this instance will create. The type that this instance will create. Gets the this that created this registration. The this that created this registration. Gets the instance for this registration. The instance for this registration. Gets or sets a value indicating whether the disposal of created instances for this registration should be suppressed or not. The default is false. Having a value of false, does not force an instance to be disposed of, though; Transient instances, for instance, will never be disposed of. Gets or sets a value indicating whether the disposal of created instances for this registration should be suppressed or not. Gets or sets a value indicating whether this registration object contains a user supplied instanceCreator factory delegate. Builds a new with the correct caching (according to the specifications of its ) applied. An . Gets the list of instances. Note that the list is only available after calling . A new array containing the instances. Initializes an already created instance and applies properties and initializers to that instance. This method is especially useful in integration scenarios where the given platform is in control of creating certain types. By passing the instance created by the platform to this method, the container is still able to apply any properties (as defined using a custom ) and by applying any initializers. The instance to initialize. Thrown when is a null reference (Nothing in VB). Thrown when the supplied is not of type . Suppressing the supplied for the given registration. The . The justification of why the warning must be suppressed. Thrown when is a null reference. Thrown when either is an empty string or when is not a valid value of . Builds a delegate for the creation of the using the supplied . The returned might be intercepted by a Container.ExpressionBuilding event, and the will have been wrapped with a delegate that executes the registered initializers that are applicable to the given (if any). The interface or base type that can be used to retrieve instances. The delegate supplied by the user that allows building or creating new instances. A delegate. Thrown when one of the arguments is a null reference. Builds a delegate for the creation of . The returned might be intercepted by a Container.ExpressionBuilding event, and the creation of the will have been wrapped with a delegate that executes the registered initializers that are applicable to the given (if any). A delegate. Thrown when one of the arguments is a null reference. Builds an that describes the creation of the using the supplied . The returned might be intercepted by a Container.ExpressionBuilding event, and the will have been wrapped with a delegate that executes the registered initializers that are applicable to the given (if any). The interface or base type that can be used to retrieve instances. The delegate supplied by the user that allows building or creating new instances. An . Thrown when one of the arguments is a null reference. Builds an that describes the creation of . The returned might be intercepted by a Container.ExpressionBuilding event, and the creation of the will have been wrapped with a delegate that executes the registered initializers that are applicable to the InstanceProducer's ServiceType (if any). An . Thrown when one of the arguments is a null reference. Implements a cache for implementations. is thread-safe can be used over multiple threads concurrently, but note that the cached instances might not be thread-safe. Initializes a new instance of the class. Initializes a new instance of the class. The container instance that the scope belongs to. Gets the container instance that this scope belongs to. The instance. Gets an instance of the given for the current scope. The type of the service to resolve. An instance of the given service type. Gets an instance of the given for the current scope. The type of the service to resolve. An instance of the given service type. Allows registering an delegate that will be called when the scope ends, but before the scope disposes any instances. During the call to all registered delegates are processed in the order of registration. Do note that registered actions are not guaranteed to run. In case an exception is thrown during the call to , the will stop running any actions that might not have been invoked at that point. Instances that are registered for disposal using on the other hand, are guaranteed to be disposed. Note that registered actions won't be invoked during a call to . The delegate to run when the scope ends. Thrown when one of the arguments is a null reference (Nothing in VB). Thrown when the scope has been disposed. Adds the to the list of items that will get disposed when the scope ends. Instances that are registered for disposal, will be disposed in opposite order of registration and they are guaranteed to be disposed when is called (even when exceptions are thrown). This mimics the behavior of the C# and VB using statements, where the method is called inside the finally block. The instance that should be disposed when the scope ends. Thrown when one of the arguments is a null reference (Nothing in VB). Thrown when the scope has been disposed. Retrieves an item from the scope stored by the given or null when no item is stored by that key. Thread-safety: Calls to this method are thread-safe, but users should take proper percussions when they call both GetItem and . The key of the item to retrieve. The stored item or null (Nothing in VB). Thrown when one of the supplied arguments is a null reference (Nothing in VB). Stores an item by the given in the scope. Thread-safety: Calls to this method are thread-safe, but users should take proper percussions when they call both and SetItem. The key of the item to insert or override. The actual item. May be null. Thrown when paramref name="key"/> is a null reference (Nothing in VB). Returns the list of instances that will be disposed of when this instance is being disposed. The list contains scoped instances that are cached in this instance, and instances explicitly registered for disposal using . The instances are returned in order of creation/registration. When Scope.Dispose is called, the scope will ensure is called on each instance in this list. The instance will be disposed in opposite order as they appear in the list. The list of instances that will be disposed of when this instance is being disposed. Releases all instances that are cached by the object. Gets the service object of the specified type. An object that specifies the type of service object to get. A service object of type serviceType -or- null if there is no service object of type . Releases all instances that are cached by the object. False when only unmanaged resources should be released. Base class for scoped lifestyles. A scoped lifestyle caches instances for the duration of an implicitly or explicitly defined scope. Such scope can be an (implicitly defined) web request or an explicitly defined Lifetime Scope. The lifetime of instances registered with a scoped lifestyle is always equal or bigger than one-instance-per-object-graph. In other words, a call to GetInstance() will never create more than one instance of such registered type. Gets the scoped lifestyle that allows Scoped registrations to be resolved direclty from the by calling . This allows multiple scopes to be active and overlap within the same logical context, such as a single thread, or an asynchronous context. Initializes a new instance of the class. The user friendly name of this lifestyle. Thrown when is null (Nothing in VB) or an empty string. Initializes a new instance of the class. The user friendly name of this lifestyle. Signals the lifestyle whether instances should be disposed or not. Thrown when is null (Nothing in VB) or an empty string. Gets the length of the lifestyle. The representing the length of this lifestyle. Allows registering an delegate that will be called when the scope ends, but before the scope disposes any instances. During the call to all registered delegates are processed in the order of registration. Do note that registered actions are not guaranteed to run. In case an exception is thrown during the call to , the will stop running any actions that might not have been invoked at that point. Instances that are registered for disposal using on the other hand, are guaranteed to be disposed. Note that registered actions won't be invoked during a call to . The instance. The delegate to run when the scope ends. Thrown when one of the arguments is a null reference (Nothing in VB). Will be thrown when there is currently no active scope for the supplied . Adds the to the list of items that will get disposed when the scope ends. The instance. The instance that should be disposed when the scope ends. Thrown when one of the arguments is a null reference (Nothing in VB). Will be thrown when there is currently no active scope for the supplied . Returns the current for this lifestyle and the given , or null when this method is executed outside the context of a scope. The container instance that is related to the scope to return. A instance or null when there is no scope active in this context. Creates a delegate that upon invocation return the current for this lifestyle and the given , or null when the delegate is executed outside the context of such scope. The container for which the delegate gets created. A delegate. This method should never return null. Creates a new instance defining the creation of the specified using the supplied with the caching as specified by this lifestyle. The interface or base type that can be used to retrieve the instances. A delegate that will create a new instance of every time it is called. The instance for which a must be created. A new instance. Creates a new instance defining the creation of the specified with the caching as specified by this lifestyle. The concrete type that will be registered. The instance for which a must be created. A new instance. Returns the current for this lifestyle and the given , or null when this method is executed outside the context of a scope. By default, this method calls the method and invokes the returned delegate. This method can be overridden to provide an optimized way for getting the current scope. The container instance that is related to the scope to return. A instance or null when there is no scope active in this context. Internal helper for string resources. Contains contextual information for creating an implementation type. Please see the Register method for more information. Gets the closed generic service type that is to be created. The closed generic service type. Gets the contextual information of the consuming component that directly depends on the resolved service. This property will return null in case the service is resolved directly from the container. The or null. Returns a list of base types and interfaces of implementationType that either equal to serviceType or are closed or partially closed version of serviceType (in case serviceType itself is generic). So: -in case serviceType is non generic, only serviceType will be returned. -If implementationType is open generic, serviceType will be returned (or a partially closed version of serviceType is returned). -If serviceType is generic and implementationType is not, a closed version of serviceType will be returned. -If implementationType implements multiple (partially) closed versions of serviceType, all those (partially) closed versions will be returned. The (open generic) service type to match. The implementationType to search. A list of types. Useful extensions on . Builds an easy to read type name. Namespaces will be omitted, and generic types will be displayed in a C#-like syntax. Ideal for reporting type names in exception messages. The type to convert. A human-readable string representation of that type. Thrown when the supplied argument is a null reference. Returns true is there is a closed version of the supplied that is assignable from the current . This method returns true when either itself, one of its base classes or one of its implemented interfaces is a closed version of ; otherwise false. The type to check. The generic type definition to match. True when type is assignable; otherwise false. Gets the single closed version of that the current is assignable from. In case none or multiple matching closed types are found, and exception is thrown. Example: When is a type class X : IX<int>, IFoo<string> and is type IX<T>: this method will return type IX<int>. The type to check. The generic type definition to match. The matching closed type. Thrown when one of the arguments is a null reference. Thrown when is not a generic type or when none of the base classes or implemented interfaces of are closed-versions of . Thrown when multiple matching closed generic types are found. Gets the list of closed versions of that the current is assignable from. Example: When is a type class X : IX<int>, IFoo<string> and is type IX<T>: this method will return type IX<int>. The type to check. The generic type definition to match. A list of matching closed generic types. Defines options to control the types returned from the GetTypesToRegister method. For a type to be returned, it should match all the conditions described by the class's properties. In other words, in case the searched assembly contains a generic type, that is both a decorator and a composite, it will only be returned by GetTypesToRegister in case both , and are set to true. Initializes a new instance of the class. Gets or sets a value indicating whether decorator types should be included in the result. The default value of this property is false. A type is considered a decorator if the type's constructor contains a parameter of the type that exactly matches the serviceType argument, supplied to the GetTypesToRegister method, or when there is a argument where T matches the serviceType argument. A boolean. Gets or sets a value indicating whether generic type definitions (types that have Type.IsGenericTypeDefinition set to true) should be included in the result. The default value for this property is false. A boolean. Gets or sets a value indicating whether composite types should be included in the result. The default value of this property is true. A type is considered a composite if the type's constructor contains a parameter of IEnumerable<T>, ICollection<T>, IList<T>, IReadOnlyCollection<T>, IReadOnlyList<T> or T[] (array of T), where T exactly matches the serviceType argument, supplied to the GetTypesToRegister method. A boolean. Provides data for and interaction with the ResolveUnregisteredType event of the . An observer can check the to see whether the unregistered type can be handled. The method can be called to register a delegate that allows creation of instances of the unregistered for this and future requests. Gets the unregistered service type that is currently requested. The unregistered service type that is currently requested. Gets a value indicating whether the event represented by this instance has been handled. This property will return true when has been called on this instance. The indication whether the event has been handled. Registers a delegate that allows creation of instances of the type expressed by the for this and future requests. The delegate will be caches and future requests will directly call that delegate. The delegate that allows creation of instances of the type expressed by the . Thrown when the is a null reference. Thrown when multiple observers that have registered to the ResolveUnregisteredType event called this method for the same type. Registers an that describes the creation of instances of the type expressed by the for this and future requests. The delegate will be cached and future requests will directly use that expression or the compiled delegate. NOTE: If possible, use the Register(Registration) overload, since this allows the analysis services to determine any configuration errors on the lifestyle of the registration. The expression that describes the creation of instances of the type expressed by the . Thrown when the is a null reference. Thrown when multiple observers that have registered to the ResolveUnregisteredType event called this method for the same type. Registers a that describes the creation of instances of the type expressed by the for this and future requests. The registration will be cached and future requests will directly call unon that registration, the expression that it generates or the delegate that gets compiled from that expression. The registration that describes the creation of instances according to the registration's lifestyle of the type expressed by the . Thrown when the is a null reference. Thrown when the is a not exactly of type where T equals the . Thrown when multiple observers that have registered to the ResolveUnregisteredType event called this method for the same type. This enumeration defines in which way the container should run the verification process. Specifies that the container performs verification only, which means that it will test whether all registrations can be constructed by iterating the registrations and letting the container create at least one instance of each registration. An will be thrown in case the configuration is invalid. Specifies that the container will run diagnostic analysis after the verification succeeded. The container will diagnose the configuration with a subset of the available diagnostic warnings, that are most likely an indication of a configuration mistake. A complete set of diagnostic warnings can be retrieved by calling Analyzer.Analyze or by viewing the container in the Visual Studio debugger, after the verification has succeeded. Visualization options for providing various information about instances. Gets or sets a value indicating whether to include lifestyle information in the visualization. The value to include life style information. Gets or sets a value indicating whether to use fully qualified type names in the visualization. The value to use fully qualified type names.