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. Xcrysden-2

    XCrySDen -- (X-Window) CRYstalline Structures and DENsities Introduction to use. XCrySDen is a cryst ...

  2. cf451C-Predict Outcome of the Game

    http://codeforces.com/problemset/problem/451/C A - Predict Outcome of the Game Time Limit:2000MS     ...

  3. [SCOI2007]修车(建图好题)

    [SCOI2007]修车 https://www.lydsy.com/JudgeOnline/problem.php?id=1070 Time Limit: 1 Sec  Memory Limit:  ...

  4. php页面的基本语法

    概述: 1. PHP 脚本在服务器上执行,然后将纯 HTML 结果发送回浏览器. 2. PHP 脚本以 <?php 开始,以 ?> 结束,可以放到文档中的任何位置. 3. 当 PHP 解析 ...

  5. VS代码页到设计页传值

    代码页  public string titleZRclass = "";   根据条件设置其值 设计页  <%=titleZRclass %>

  6. 【转】MEF程序设计指南三:MEF中组合部件(Composable Parts)与契约(Contracts)的基本应用

    按照MEF的约定,任何一个类或者是接口的实现都可以通过[System.ComponentModel.Composition.ExportAttribute] 特性将其定义为组合部件(Composabl ...

  7. 面向对象设计模式纵横谈:Prototype 原型模式(笔记记录)

       有一段时间没写东西了,今天继续把没写完的设计模式写完,今天这堂课是创建型设计模式的最后一堂课,原型设计模式,它同样也是解决了对象在创建的过程中的解耦合的情况,面对变化使代码更稳定,更准确的说是使 ...

  8. Linux下搭建gtk+2.0开发环境

    1.执行如下命令,检查系统是否已安装gtk+ pkg-config --list-all |grep gtk 若命令提示如下,则系统已安装gtk+,否则未安装. 2.若未安装,则执行如下命令进行安装 ...

  9. code4906 删数问题

    题目: 键盘输入一个高精度的正整数n(<=240位), 去掉任意s个数字后剩下的数字按原左右次序将组成一个新的正整数. 编程对给定的n和s,寻找一种方案,使得剩下的数最小. Simple Inp ...

  10. Codeforces 710C. Magic Odd Square n阶幻方

    C. Magic Odd Square time limit per test:1 second memory limit per test:256 megabytes input:standard ...