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).
Inheritance Hierarchy
SimpleInjectorInstanceProducer
SimpleInjectorInstanceProducerTService
Namespace: SimpleInjector
Assembly: SimpleInjector (in SimpleInjector.dll) Version: 5.3.0
Syntax
The InstanceProducer type exposes the following members.
Constructors
Name | Description | |
---|---|---|
InstanceProducer | Initializes a new instance of the InstanceProducer class. |
Properties
Name | Description | |
---|---|---|
ImplementationType |
Gets the originally registered implementation type. Note that the actual type, returned by
GetInstance, will be different from ImplementationType when
decorators or interceptors are applied. This property will always return the originally registered
implementation type. In case the implementation type is unknown, which happens for instance when
registering FuncTResult delegates, the service type is returned.
| |
Lifestyle |
Gets the Lifestyle 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.
| |
Registration | Gets the Registration instance for this instance.
Please note that, when decorators are applied, this instance is replaces and will become the
registration for the outermost decorator. | |
ServiceType | Gets the service type for which this producer produces instances. |
Methods
Name | Description | |
---|---|---|
BuildExpression |
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.
| |
FromExpression |
Creates a new InstanceProducer based on the given serviceType
and expression where the expression will be used as-is;
no interception (using ExpressionBuilt) such as
decorators will be applied.
| |
GetInstance | Produces an instance. | |
GetRelationships |
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).
| |
VisualizeObjectGraph |
Builds a string representation of the object graph with the current instance as root of the
graph.
| |
VisualizeObjectGraph(VisualizationOptions) |
Builds a string representation of the object graph with the current instance as root of the
graph.
|
Remarks
Examples
Interface1
Interface1Decorator
C#
var container = new Container(); // ServiceImpl implements both Interface1 and Interface2. var registration = Lifestyle.Singleton.CreateRegistration<ServiceImpl, ServiceImpl>(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);
See Also