Not complex Autofac injection, not complex Autofac Injection

Source: Internet
Author: User

Not complex Autofac injection, not complex Autofac Injection

Private static void SetAutofacWebAPI () {var builder = new ContainerBuilder (); # region configuration registration method string dataType = ConfigurationManager. appsetetype ["dataBaseType"]. toString (). toLower (); // var data = Assembly. load ("Model"); // Load the specified Assembly var data2 = Assembly. load ("MvcAdmin. service "); // load the specified Assembly switch (dataType) {case" mssql ": builder. registerAssemblyTypes (data2 ). where (a =>. fullName. contains ("MvcAdmin. service. MSSQLServer ")). asImplementedInterfaces (); break; case "mysql": builder. registerAssemblyTypes (data2 ). where (a =>. fullName. contains ("MvcAdmin. service. mySQLServer ")). asImplementedInterfaces (); break; default: // builder. registerAssemblyTypes (data )//. where (a =>. fullName. contains ("Model. MYSQL ")). asImplementedInterfaces (); builder. registerAssemblyTypes (data2 ). where (a =>. fullName. contains ("MvcAdmin. service. mySQLServer ")). asImplementedInterfaces (); break ;}# endregion builder. registerControllers (Assembly. getExecutingAssembly (); var container = builder. build (); DependencyResolver. setResolver (new AutofacDependencyResolver (container ));}

It can be seen that a database option is added to web. config. If it is not added, the default option is displayed. Some people have said that the web. config configuration is too complicated.

This complex articleHttp://www.cnblogs.com/RainbowInTheSky/p/4531786.html

The above code is used in the small background of open-source. Address:Http://code.taobao.org/p/MvcAdmin/src/You can check the startup item code.

In addition, the Autofac entry is attached:

Http://www.cnblogs.com/liping13599168/archive/2011/07/16/2108209.html (console walkthrough)

Http://www.cnblogs.com/jiagoushi/p/4084145.html (property injection)

Http://www.cnblogs.com/n-pei/archive/2013/01/24/2875674.html (mvc walkthrough)

Related Article

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.