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

  • 相关阅读:
    JS中的call、apply、bind 用法解疑
    style、currentStyle、getComputedStyle(不同浏览器获取css样式)区别介绍
    Ajax 整理总结(进阶)
    Ajax 整理总结(入门)
    js_面向对象编程
    李炎恢bootstarp_项目实战__瓢城企业(注释+源码)
    bootstrap学习笔记--bootstrap排版类的使用
    bootstrap学习笔记--bootstrap网格系统
    对mysql快速批量修改,查重
    MyISAM 和 InnoDB 的区别与优化
  • 原文地址:https://www.cnblogs.com/mumue/p/2804721.html
Copyright © 2011-2022 走看看