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)