autofac学习
Instance Scope
1、instance per dependency (the default)
builder.RegisterType<classes>();等价于
builder.RegisterType<classes>().InstencePerDenpendency();
每次都创建一个新的依赖
2、single instance
builder.RegisterType<classes>().SingleInstance();
单例,每次都返回同一个
3、instance per lifetime scope
builder.RegisterType<classes>().InstancePerLifetimeScope();
在同一个生命周期中返回同一个实例
官方文档eg:
using(var scope1 = container.BeginLifetimeScope())
{
for(var i = ; i < ; i++)
{
// Every time you resolve this from within this
// scope you'll get the same instance.
var w1 = scope1.Resolve<Worker>();
}
} using(var scope2 = container.BeginLifetimeScope())
{
for(var i = ; i < ; i++)
{
// Every time you resolve this from within this
// scope you'll get the same instance, but this
// instance is DIFFERENT than the one that was
// used in the above scope. New scope = new instance.
var w2 = scope2.Resolve<Worker>();
}
}
scope1中每次循环返回同一个Worker实例
scope2中每次循环返回同一个Worker实例
但是,scope1中的实例和scoper2中的实例并不是同一个
4、instance per matching lifetime scope
没看懂
builder.RegisterType<classes>.InstancePerMatchingLifetimeScope("my");
5、instance per request
每次请求返回一个实例(在这个请求的lifetime scope)
per request是matching lifetime scope的一种
InstancePerRequest() 最终执行Autofac.Core.Lifetime.MatchingScopeLifetimeTags.AutofacWebRequest
等价于:builder.RegisterType<classes>.InstancePerMatchingLifetimeScope("AutofacWebRequest");
autofac学习的更多相关文章
- autofac 学习记录
builder.RegisterModule(new ConfigurationSettingsReader()); 需要注册上面一句才能读到.config里的节点,xml配置方式如下 <con ...
- AutoFac学习摘要
依赖注入(控制反转)常见的依赖注入工具:AutoFac,Spring.Net,Unity等依赖注入的方式:1.通过构造函数进行注入2.通过属性进行注入 注意:在项目中AutoFac的注入有两次,第一次 ...
- Autofac学习之三种生命周期:InstancePerLifetimeScope、SingleInstance、InstancePerDependency
InstancePerLifetimeScope:同一个Lifetime生成的对象是同一个实例 SingleInstance:单例模式,每次调用,都会使用同一个实例化的对象:每次都用同一个对象: In ...
- Autofac学习之三种生命周期:InstancePerLifetimeScope、SingleInstance、InstancePerDependency 【转载】
InstancePerLifetimeScope:同一个Lifetime生成的对象是同一个实例 SingleInstance:单例模式,每次调用,都会使用同一个实例化的对象:每次都用同一个对象: In ...
- IoC容器Autofac学习笔记
一.一个没有使用IoC的例子 IoC的全称是Inversion of Control,中文叫控制反转.要理解控制反转,可以看看非控制反转的一个例子. public class MPGMovieList ...
- 依赖反转Ioc和unity,autofac,castle框架教程及比较
1.依赖倒置的相关概念 http://www.cnblogs.com/fuchongjundream/p/3873073.html IoC模式(依赖.依赖倒置.依赖注入.控制反转) 2.依赖倒置的方式 ...
- 【框架学习与探究之依赖注入--Autofac】
声明 本文欢迎转载,原文地址:http://www.cnblogs.com/DjlNet/p/7603642.html 序 同样的又是一个双11如期而至,淘宝/天猫实时数据显示,开场3分钟总交易额突破 ...
- autofac 初步学习
//数据处理接口 public interface IDal<T> where T : class { void Insert (T model); void Update(T model ...
- .Net Core 学习之路-AutoFac的使用
本文不介绍IoC和DI的概念,如果你对Ioc之前没有了解的话,建议先去搜索一下相关的资料 这篇文章将简单介绍一下AutoFac的基本使用以及在asp .net core中的应用 Autofac介绍 组 ...
随机推荐
- Spring MVC零配置(全注解)(版本5.0.7)
// 核心配置类 package spittr.config; import org.springframework.web.servlet.support.AbstractAnnotationCon ...
- Python列表知识补充
1.import this Python之禅,圣经. >>> import this The Zen of Python, by Tim Peters Beautiful is b ...
- Qt(Mac) 进程的启动
试了半天,终于成功了!!!!(教程都是Windows的) 1.与Windows不一样,Mac的要在了路径前加上open: 2.例 图为把一个按钮与TextEdit程序进程联系,点击后就可以启动Text ...
- P3768 简单的数学题 杜教筛+推式子
\(\color{#0066ff}{ 题目描述 }\) 由于出题人懒得写背景了,题目还是简单一点好. 输入一个整数n和一个整数p,你需要求出(\(\sum_{i=1}^n\sum_{j=1}^n ij ...
- CF796B Find The Bone
Zane the wizard is going to perform a magic show shuffling the cups. There are n cups, numbered from ...
- HTTP协议和WebSocket协议(一)
转自:https://www.jianshu.com/p/0e5b946880b4# HTTP HTTP的地址格式如下: http_URL = "http:" "//&q ...
- winfom实现关闭后一直运行
using PLog; using System; using System.Collections.Generic; using System.Diagnostics; using System.L ...
- Luogu P4095 [HEOI2013]Eden 的新背包问题 思维/动规
当时一直在想前缀和...多亏张队提醒... 从1到n背次包,保存每一个状态下的价值,就是不要把第一维压掉:再从n到1背一次,同样记住每种状态: 然后询问时相当于是max(前缀+后缀),当然前缀后缀中间 ...
- 【bzoj2935】[Poi1999]原始生物
2935: [Poi1999]原始生物 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 145 Solved: 71[Submit][Status][D ...
- css过渡transition
定义 过渡transition是一个复合属性,包括transition-property.transition-duration.transition-timing-function.transiti ...