Automatic generation of Basecontroller injection service Interfaces
Public Static stringDatatabletoautoface (DataTable DT,stringnameSpace) {StringBuilder SB=NewStringBuilder (); StringBuilder sbcontent=NewStringBuilder (); for(vari =0; i < dt. Rows.Count; i++) {Sbcontent.appendformat (@"Public i{0} i{0} {{get {{return dependencyresolver.current.getservice<i{0}> () as i{0 }; }} }}"Dt. rows[i]["name"] +"Service"); } sb. AppendFormat (@"using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using autofac;using {0}. mapping;using {0}. Iservice;namespace {0}. uibase.controllers{{//<summary>///System Controller Layer injection portal (Unified generation Please do not modify the file)///</summary> public partial class Basecontroller:controller {{1} }}}", NameSpace, sbcontent); returnsb. ToString (); }
View Code
Global.asax
Public Static voidregisterroutes (routecollection routes) {routes. Ignoreroute ("{Resource}.axd/{*pathinfo}"); Routes. MapRoute (Name:"Default", URL:"{Controller}/{action}/{id}", defaults:New{controller ="Home", action ="Index", id =urlparameter.optional}); } protected voidApplication_Start () {varBuilder =NewContainerbuilder (); Builder. Registermodule (NewConfigurationsettingsreader ("naming")); Assembly[] ASM=pluginhelper.getallassembly (). ToArray (); //Assembly.LoadFrom (path.getfilenamewithoutextension ("SharpSvn.dll"));Builder. Registerassemblytypes (ASM); Builder. Registercontrollers (assembly.getexecutingassembly ()); Builder. Registerassemblytypes (assembly.getexecutingassembly ()); Builder. Registermodelbinderprovider (); Builder. Registerfilterprovider ();//Register Filter varcontainer =Builder. Build (); Dependencyresolver.setresolver (NewAutofacdependencyresolver (container)); Arearegistration.registerallareas (); RegisterRoutes (routetable.routes); }
View Code
Pluginhelper
View Code
Configuration file
<configSections> <section name="Module"Type="Autofac.Configuration.SectionHandler, Autofac.configuration"/> </configSections> <lq-module> <modules> <module type="namespace. Service, Namespace"></module> <module type="namespace. Repository, name space"></module> </modules> </lq-module></configuration>Web. config< naming > <files> <file name="Config/module.config"section="Module"/> </files> </naming >
View Code
SQL Table Auto-Generate net bottom-controller AUTOFAC injection