zoukankan      html  css  js  c++  java
  • Unity Lifetime

    There are 6 types of Lifetime Managers available to work with.

    TransientLifetimeManager. For this lifetime manager Unity creates and returns a new instance of the requested type for each call to the Resolve or ResolveAll method. This lifetime manager is used by default for all types registered using the RegisterType, method unless you specify a different lifetime manager.

    ContainerControlledLifetimeManager which registers an existing object as a singleton instance. For this lifetime manager Unity returns the same instance of the registered type or object each time you call the Resolve orResolveAll method or when the dependency mechanism injects instances into other classes. 

    HierarchicalLifetimeManagerFor this lifetime manager, as for theContainerControlledLifetimeManager, Unity returns the same instance of the registered type or object each time you call the Resolve or ResolveAll method or when the dependency mechanism injects instances into other classes. The distinction is that when there are child containers, each child resolves its own instance of the object and does not share one with the parent. When resolving in the parent, the behavior is like a container controlled lifetime; when resolving the parent and the child you have different instances with each acting as a container-controlled lifetime.

    PerResolveLifetimeManager. For this lifetime manager the behavior is like a TransientLifetimeManager, but also provides a signal to the default build plan, marking the type so that instances are reused across the build-up object graph. In the case of recursion, the singleton behavior applies where the object has been registered with thePerResolveLifetimeManager. The following example uses the PerResolveLifetimeManager

    PerThreadLifetimeManager. For this lifetime manager Unity returns, on a per-thread basis, the same instance of the registered type or object each time you call the Resolve or ResolveAll method or when the dependency mechanism injects instances into other classes. This lifetime manager effectively implements a singleton behavior for objects on a per-thread basis. PerThreadLifetimeManager returns different objects from the container for each thread.

    ExternallyControlledLifetimeManager. The ExternallyControlled LifetimeManager class provides generic support for externally managed lifetimes. This lifetime manager allows you to register type mappings and existing objects with the container so that it maintains only a weak reference to the objects it creates when you call theResolve or ResolveAll method or when the dependency mechanism injects instances into other classes based on attributes or constructor parameters within that class. This allows other code to maintain the object in memory or dispose it and enables you to maintain control of the lifetime of existing objects or allow some other mechanism to control the lifetime.

    With this we have seen how to resolve Dependencies using Unity frame work and significance of Lifetime Managers.

    Origin Url:http://www.codeproject.com/Articles/424743/MVC-DI-Unity-with-Lifetime-Manager

  • 相关阅读:
    信号实现父子进程之间的同步sigsuspend的作用
    java中四种操作(DOM、SAX、JDOM、DOM4J)xml方式详解与比较
    [置顶] iOS学习笔记45—本地通知UILocalNotification
    没有母亲的母亲节似乎来得早一些
    poj 2007 Scrambled Polygon(凸多边形顶点输出)
    MySQL架构设计相关的方式方法和软件介绍
    1、单机运行环境搭建之 --CentOS6.9安装配置JDK7
    更改root密码一例
    3、单机运行环境搭建之 --CentOS6.5安装配置Tengine
    Tomcat7 安装使用及jvm连接数参数调优
  • 原文地址:https://www.cnblogs.com/mumue/p/2804721.html
Copyright © 2011-2022 走看看