Small copy: Choose Unity's Object Lifecycle Administrator

Source: Internet
Author: User

The Unity framework provides several life cycle administrators with similarities and differences. It's hard to get dizzy when you first touch.
Make this small copy, just to help yourself to understand and remember. If you also use untiy, or can refer to see.

Words say:

  • Transientlifetimemanager: A new object is created each time it is parsed, and the Unity container does not save the object's reference (that is, the container is not responsible for releasing the object). This control mode is generally called Transient.
  • ContainerControlledLifetimeManager: Each time the parse is fixed, it returns the same existing object and releases the object when the container itself is destroyed. The effect of this life cycle pattern is equivalent to Singleton mode. This is also the default life cycle administrator when calling the RegisterInstance method.
  • Perresolvelifetimemanager: Similar to Transientlifetimemanager, the main difference is that it reuses the same object during deep parsing, rather than creating new objects each time.
  • Perthreadlifetimemanager: Basically, this life cycle is equal to the thread-wide Singleton. Its behavior is similar to ContainerControlledLifetimeManager, except that it depends on the thread to decide whether to create a new object. This life cycle administrator is not responsible for releasing objects.
  • Externallycontrolledlifetimemanager: As with ContainerControlledLifetimeManager, it has a Singleton effect, but the main difference is that Externallycontrolledlifetimemanager is a weak reference to a saved object (weak reference). In this way, you can take full control of the time the object is disposed of, such as immediately calling its Dispose method when the object is exhausted to dispose of the object. Obviously, this life cycle administrator is not responsible for releasing objects.
  • Hierarchicallifetimemanager: Used in a class container, that is, the container itself contains a sub-container of the occasion. Basically, this life cycle behavior equates to ContainerControlledLifetimeManager plus additional control over the child container: the sub-container has its own Singleton scope and does not share the same object with the parent container.
  • Perrequestlifetimemanager: This life cycle administrator applies only to Web applications. It ensures that the same object is always returned when a type is resolved within the same HTTP request. Basically, it is a Singleton within the scope of an HTTP request.

Small copy: Choose Unity's Object Lifecycle Administrator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.