標籤:style blog http color io ar strong art sp
1、InstancePerDependency
對每一個依賴或每一次調用建立一個新的唯一的執行個體。這也是預設的建立執行個體的方式。
官方文檔解釋:Configure the component so that every dependent component or call to Resolve() gets a new, unique instance (default.)
2、InstancePerLifetimeScope
在一個生命週期域中,每一個依賴或調用建立一個單一的共用的執行個體,且每一個不同的生命週期域,執行個體是唯一的,不共用的。
官方文檔解釋: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
在一個做標識的生命週期域中,每一個依賴或調用建立一個單一的共用的執行個體。打了標識了的生命週期域中的子標識域中可以共用父級域中的執行個體。若在整個繼承層次中沒有找到打標識的生命週期域,則會拋出異常:DependencyResolutionException。
官方文檔解釋: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
在一個生命週期域中所擁有的執行個體建立的生命週期中,每一個相依元件或調用Resolve()方法建立一個單一的共用的執行個體,並且子生命週期域共用父生命週期域中的執行個體。若在繼承層級中沒有發現合適的擁有子執行個體的生命週期域,則拋出異常:DependencyResolutionException。
官方文檔解釋: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
每一次相依元件或調用Resolve()方法都會得到一個相同的共用的執行個體。其實就是單例模式。
官方文檔解釋:Configure the component so that every dependent component or call to Resolve() gets the same, shared instance.
6、InstancePerHttpRequest
在一次Http請求上下文中,共用一個組件執行個體。僅適用於asp.net mvc開發。
官方文檔解釋:Share one instance of the component within the context of a single HTTP request.
轉載自:http://blog.csdn.net/dhx20022889/article/details/9061483
Autofac建立執行個體的方法總結[轉]