Autofac实例生命周期
            时间:2014-01-14 19:26:11  
            收藏:0  
            阅读:1345
        
        
        1.默认,每次请求都会返回一个实例
 
 
builder.RegisterType<X>().InstancePerDependency();
2.Per Lifetime Scope:这个作用域适用于嵌套的生命周期。一个使用Per Lifetime 作用域的component在一个 nested lifetime scope内最多有一个实例。
| 1 | builder.RegisterType<X>().InstancePerLifetimeScope(); | 
3.基于线程或者Context上下文的请求,返回一个单例实例,在Controller的一个View页面执行时包含了整个Context上下文处理,这种属于第二种情况的一个例子
| 1 | builder.RegisterType<OpenIdRelyingPartyService>().As<IOpenIdRelyingPartyService>().InstancePerHttpRequest(); | 
4.单例模式:所有的请求只会返回一个单例
| 1 | builder.RegisterType<X>().SingleInstance(); | 
Don’t resolve from the root container. Always resolve from and then release a lifetime scope.
原文:http://www.cnblogs.com/xiaoweinet/p/3512255.html
            评论(0)
        
        
         
        