Autofac instance creation method summary [go], autofac instance
1. InstancePerDependency
Create a unique instance for each dependency or each call. This is also the default instance creation method.
Official documentation explanation: Configure the component so that every dependent component or call to Resolve () gets a new, unique instance (default .)
2. instanceperlifetimesloud
In a lifecycle domain, each dependency or call creates a single shared instance, and each different lifecycle domain, the instance is unique and not shared.
Official documentation explanation: 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. instancepermatchinglifetimes.pdf
In a lifecycle domain that is identified, each dependency or call creates a single shared instance. Instances in the parent domain can be shared in the sub-ID domain in the lifecycle domain identified by the user. If the identified lifecycle field is not found in the entire inheritance level, a DependencyResolutionException is thrown.
Official documentation explanation: Configure the component so that every dependent component or call to Resolve () within a ilifetimes1_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 in a lifecycle domain, each dependent component or the Resolve () method is called to create a single shared instance, the sub-lifecycle domain shares instances in the parent lifecycle domain. If no appropriate lifecycle domain with sub-instances is found at the inheritance level, the DependencyResolutionException is thrown.
Official documentation explanation: Configure the component so that every dependent component or call to Resolve () within a ilifetimessponcreated 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
Each time the dependent component or the Resolve () method is called, an identical shared instance is obtained. This is actually the singleton mode.
Official documentation explanation: Configure the component so that every dependent component or call to Resolve () gets the same, shared instance.
6. InstancePerHttpRequest
Share a component instance in an Http request context. Only applicable to asp.net mvc development.
Official Document explanation: Share one instance of the component within the context of a single HTTP request.
Reprinted from: http://blog.csdn.net/dhx20022889/article/details/9061483
How to Use autofacmvc4
How does one create a subclass instance in java to call the override method of the parent class?
A friend of the Foible clause is incorrect.
B B B = new B (); in this way, the object of the subclass is actually instantiated. Note: The memory is still a subclass object.
(A) B). m (); On the surface, it looks like A parent class object, but because the memory is A subclass object, it is called as A subclass method.
A B = new B ();
B. m ();
This method is actually effective with what you write. Although it is applied to the parent class, the subclass method (that is, the method of the subclass) is called because the subclass overrides the method of the parent class: method implementation, and finally in the subclass ).
Therefore, the summary is as follows:
If the subclass does not override the method of the parent class, when calling the method of the parent class, it is actually implemented in the memory of the parent class. You can call the parent class method.
If the subclass overrides the method of the parent class, even though you have taken the shape of the parent class, the implementation of this method is still in the subclass due to memory or subclass, therefore, the instantiated object cannot call the parent class. In this case, only the super keyword can be used.
If static is used, we will not discuss it. If you are not satisfied, you can send a message to continue the discussion.