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创建实例的方法总结[转]的更多相关文章

  1. Autofac创建实例的方法总结 【转】

    Autofac创建实例的方法总结   1.InstancePerDependency 对每一个依赖或每一次调用创建一个新的唯一的实例.这也是默认的创建实例的方式. 官方文档解释:Configure t ...

  2. [转] Autofac创建实例的方法总结

    1.InstancePerDependency 对每一个依赖或每一次调用创建一个新的唯一的实例.这也是默认的创建实例的方式. 官方文档解释:Configure the component so tha ...

  3. Autofac创建实例的方法总结

    1.InstancePerDependency 对每一个依赖或每一次调用创建一个新的唯一的实例.这也是默认的创建实例的方式. 2.InstancePerLifetimeScope 在一个生命周期域中, ...

  4. 关于Java中的几种特殊类与接口,及特殊的创建实例的方法

    Java中有一些特殊的类,在教材中讲解的不深,但是确实非常有用的,这里总结一下,里面用到的有网上搜到的内容,这里表示下感谢. 一.成员内部类 成员内部类是在一个内中定义的另外一个类,这个类属于其上的类 ...

  5. 从ICassFactory为CLSID为{17BCA6E8-A950-497E-B2F9-AF6AA475916F}的COM组件创建实例失败问题解决方法

    从ICassFactory为CLSID为{17BCA6E8-A950-497E-B2F9-AF6AA475916F}的COM组件创建实例失败,原因是出现以下错误:c001f011.(Microsoft ...

  6. Spring学习--静态工厂方法、实例工厂方法创建 Bean

    通过调用静态工厂方法创建 bean: 调用静态工厂方法创建 bean 是将对象创建的过程封装到静态方法中 , 当客户端需要对象时 , 只需要简单地调用静态方法 , 而不需要关心创建对象的细节. 要声明 ...

  7. C#反射动态创建实例并调用方法

    在.Net 中,程序集(Assembly)中保存了元数据(MetaData)信息,因此就可以通过分析元数据来获取程序集中的内容,比如类,方法,属性等,这大大方便了在运行时去动态创建实例. MSDN解释 ...

  8. IoC容器Autofac之实例优化(三)

    回顾之前的代码 //这个类的作用是筛选出MPG类型的电影 public class MPGMovieLister { public Movie[] GetMPG() { var finder = Mo ...

  9. 速战速决 (5) - PHP: 动态地创建属性和方法, 对象的复制, 对象的比较, 加载指定的文件, 自动加载类文件, 命名空间

    [源码下载] 速战速决 (5) - PHP: 动态地创建属性和方法, 对象的复制, 对象的比较, 加载指定的文件, 自动加载类文件, 命名空间 作者:webabcd 介绍速战速决 之 PHP 动态地创 ...

随机推荐

  1. ReportViewer工具栏功能扩展[手动设置打印/导出按钮]

    ReportViewer在IE11后打印按钮就存在兼容问题,火狐,谷歌也存在打印按钮显示的兼容性问题,本资料就是解决ReportViewer打印按钮显示的问题, 通过自己写脚本添加到DOM里面让所有浏 ...

  2. SpringBoot中使用消息中间件Kafka实现Websocket的集群

    1.在实际项目中,由于数据量的增大及并发数的增多,我们不可能只用一台Websocket服务,这个时候就需要用到Webscoket的集群.但是Websocket集群会遇到一些问题.首先我们肯定会想到直接 ...

  3. phpStudy7——MySql数据库的增删查改

    1. 添加数据: //添加数据 $strsql = "insert into user_info(userId,userName,phoneNumber,userScore,dataTime ...

  4. Python调shell

    os.system(cmd) 函数返回cmd的结束状态码,阻塞调用. os.popen(cmd) 函数返回cmd的标准输出,阻塞调用. (status, output) = commands.gets ...

  5. 1-QT-文件操作

    Qt文本文件的读写操作 Qt文件操作详解(创建.写入.删除.INI.XML文件等 二进制文件的读写文件可以使用QFile类.QStream文本文件的读写建议使用QTextStream类,它操作文件更加 ...

  6. cin 不能直接读入空格,可以用getline(PAT统计字符数)

    #include <iostream>#include <cstring>using namespace std; int main(){    string str;     ...

  7. TeamCity+Rancher+Docker实现.Net Core项目DevOps(目前成本最小的DevOps实践)

    1.准备项 1.1.服务器一台,1H4G(更小内存应该也可以,自行测试),系统:Ubuntu 16.04 64位 1.2.数据库一个,MYSQL,MSSQL都可以(还有其他的,自行配置),教程是MSS ...

  8. SNP问题大集锦

    SNP问题大集锦 [2017-01-19]       最近小编对基因检测很感兴趣,也跟风去测了一下,这一测不要紧,吓得小编几天没睡着觉,这不,检测报告上称小编的减肥能力弱,虽然小编一家都是胖子,唯有 ...

  9. gdb 调试带参数程序

    在gdb中,运行程序使用r或是run命令. 程序的运行,你有可能需要设置下面四方面的事. 1.程序运行参数. set args 可指定运行时参数.(如:set args 10 20 30 40 50) ...

  10. 2014.1.14 struts 的default.properties 配置文件详述

    转自  http://justsee.iteye.com/blog/723993 Struts 2框架有两个核心配置文件:struts.xml和struts.properties 其中struts.x ...