IoC ~ Efficient Autofac
There is no doubt that Microsoft's favorite IoC container is not spring.net, unity but Autofac, because of its efficiency, because of its simplicity, so it is also used for Microsoft-led orchard projects
illustrates the use of an Autofac.
Let's call it now:
In the next lecture, I will talk about the use of Autofac in specific projects for orchard projects.
Now look at its life cycle
1、InstancePerDependency
Create a new unique instance for each dependency or call. This is also the default way to create instances.
Official documentation explains: Configure the component so that every dependent component or call to Resolve() gets a new, unique instance (default.)
2、InstancePerLifetimeScope
In a lifecycle domain, each dependency or call creates a single shared instance, and for each different lifecycle domain, the instance is unique and not shared.
Official documentation explains: Configure the component so that every dependent component or call to Resolve() within a single ILifetimeScope gets the same, shared instance. Dependent components in different lifetime scopes will get different instances.
3、InstancePerMatchingLifetimeScope
In an identified lifecycle domain, each dependency or call creates a single shared instance. Instances in the parent domain can be shared in the child identity domain of the identified lifecycle domain. If no identified lifecycle domain is found in the entire inheritance hierarchy, an exception is thrown: DependencyResolutionException.
Official documentation explains: Configure the component so that every dependent component or call to Resolve() within a ILifetimeScope tagged with any of the provided tags value gets the same, shared instance. Dependent components in lifetime scopes that are children of the tagged scope will share the parent's instance. If no appropriately tagged scope can be found in the hierarchy an DependencyResolutionException is thrown.
4、InstancePerOwned
In the lifecycle of an instance created by an instance owned in a lifecycle domain, each dependent component or call to the Resolve() method creates a single shared instance, and the child lifecycle domain shares the instances in the parent lifecycle domain. If no suitable lifecycle domain with child instances is found in the inheritance hierarchy, an exception is thrown: DependencyResolutionException.
The official documentation explains:
Configure the component so that every dependent component or call to Resolve() within a ILifetimeScope created by an owned instance gets the same, shared instance. Dependent components in lifetime scopes that are children of the owned instance scope will share the parent's instance. If no appropriate owned instance scope can be found in the hierarchy an DependencyResolutionException is thrown.
5、SingleInstance
Every time you depend on a component or call the Resolve() method, you get the same shared instance. In fact, it is a singleton model.
Official documentation explains: Configure the component so that every dependent component or call to Resolve() gets the same, shared instance.
6、InstancePerHttpRequest
In the context of an Http request, share an instance of a component. Available for asp.net MVC development only.
|