The difference between Registertype and registerinstance in UnityContainer

Source: Internet
Author: User

Both of these registration methods are used in the application, the following is their own understanding

RegisterInstance registering a single case mode

1             _container. Registerinstance<inavigationservice>(navigationservice); 2             _container. Registerinstance<isessionstateservice>(sessionstateservice); 3             _container. Registerinstance<ieventaggregator>(eventaggregator); 4             _container. Registerinstance<iresourceloader> ( new Resourceloaderadapter (new Resourceloader ()));         

Registered objects that have been instantiated, each call to resolve to remove the registered object is a unique singleton

Registertype Registration Type

1             _container. Registertype<iproductcatalogrepository, productcatalogrepository>(); 2             _container. Registertype<ishoppingcartrepository, shoppingcartrepository>(); 3             _container. Registertype<icheckoutdatarepository, checkoutdatarepository>(); 4             _container. Registertype<iorderrepository, orderrepository> ();    

Only when the resolve is called, the registered object is instantiated, multiple calls are made, several objects are instantiated repeatedly

Can be added type ContainerControlledLifetimeManager also registered as a singleton

1             _container. Registertype<iproductcatalogservice, productcatalogserviceproxy> (new  ContainerControlledLifetimeManager ()); 2             _container. Registertype<iorderservice, orderserviceproxy> (new  ContainerControlledLifetimeManager ()); 3             _container. Registertype<ishoppingcartservice, shoppingcartserviceproxy> (new ContainerControlledLifetimeManager ());    

1

            _container. Registertype<iproductcatalogrepository, productcatalogrepository> (new ContainerControlledLifetimeManager ());

2

            _container. Registerinstance<iproductcatalogrepository> (new

1 and 2, the individual understanding of the time is different, 1 in the first call through resolve, 2 at the time of registration to instantiate.

The difference between Registertype and registerinstance in UnityContainer

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.