SQL Table Auto-Generate net bottom-controller AUTOFAC injection

Source: Internet
Author: User

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


 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


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

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.