. Net Core Linux centos7 line-IOC module

Source: Internet
Author: User

The. NET core can be described as a new IOC template , defined under Microsoft.Extensions.DependencyInjection. Provides a standard set of interfaces. and provides the default implementation. and a wide range of uses, everywhere embodies the IOC design ideas.

In the Configureservices method of Startup, the service is centrally configured. You can see that the default . NET core MVC default project has injected us with a lot of services. See the note also understand, there is nothing particularly good explanation (^_^).

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/161654/201606/161654-20160627185740249-453753381. PNG "style=" margin:0px;padding:0px;border:none; "/>

The last 2 lines of code are injection of custom configuration. Need support for Microsoft.Extensions.Options.ConfigurationExtensions package

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/161654/201606/161654-20160627185740671-283114581. PNG "style=" margin:0px;padding:0px;border:none; "/>

AddOptions provides management, caching, and configuration change automatic support services for ioptions<pocomodel>, where changes to the configuration file are automatically reflected in the application and the application does not need to be restarted automatically. Unlike the previous web. config. any changes will be restarted automatically.

Configure<t> (iconfiguration). represents the contents of the configuration from the configuration file.

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/161654/201606/161654-20160627185741124-56728783. PNG "style=" margin:0px;padding:0px;border:none; "/>

Indexsetting is a new model, the configuration item.

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/161654/201606/161654-20160627185741749-1419332676. PNG "style=" margin:0px;padding:0px;border:none; "/>

Indexsetting in the configuration file

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/161654/201606/161654-20160627185742140-657462849. PNG "style=" margin:0px;padding:0px;border:none; "/>

currently , the. NET Core IOC has 3 ways to get service.

1.ctor injection.

2.Action Parameter Injection

3. How to get the container

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/161654/201606/161654-20160627185742796-1453313367. PNG "style=" margin:0px;padding:0px;border:none; "/>

Of course, this approach may be sufficient to deal with the general situation. But the reality is obviously not like that. Usually we need more powerful IOC lib. Currently the official recommendation of the more powerful IOC lib. is also the industry famous AUTOFAC. AUTOFAC the introduction of the garden a lot of, and write very detailed, very good. It's not a lot of introductions.

Official document:http://docs.autofac.org/en/latest/integration/aspnetcore.html

There are several main differences between the ASP and ASP.

1.Use Instanceperlifetimescope instead of instanceperrequest.

Simplicity is the unification of the life cycle.

2.No more dependencyresolver.

without the previous Dependencyresolver entrance.

3.NO Manual Controller registration.

It is no longer necessary to register your own controllerfactory, including the middleware in Owin.

Need to use it and of course need to add it

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/161654/201606/161654-20160627185743515-325688954. PNG "style=" margin:0px;padding:0px;border:none; "/>

for Startup of the configureservices method to do some modification

650) this.width=650; "Src=" http://images2015.cnblogs.com/blog/161654/201606/161654-20160627185744031-534707792. PNG "style=" margin:0px;padding:0px;border:none; "/>

with any third-party IOC, you need to return IServiceProvider. Replaces the default IServiceProvider for the system . Otherwise it will not take effect.

Then create the AUTOFAC build, as usual, we can happily use the AUTOFAC.


. Net Core Linux centos7 line-IOC module

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.