手动搭建ABP2.1.3——基础框架

一、基础层搭建

1,创建一个空解决方案 

2,层结构

Demo.Core[v:4.6.1]:类库

Demo.EntityFramework[v:4.6.1]:类库(引用Demo.Core)

Demo.Application[v:4.6.1]:类库(引用Demo.Core)

Demo.WebApi[v:4.6.1]:类库(引用Demo.Application)

Demo.Web[v:4.6.1]:WebMvc5.X(引用Demo.Core、Demo.EntityFramework、Demo.Application、Demo.WebApi)

二、Demo.Core

 1,NuGet安装Abp2.1.3

 2,添加Module类

namespace Demo.Core
{
    public class DemoCoreModule:AbpModule
    {
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
        }
    }
}

三、Demo.EntityFramework

 1,NuGet安装Abp.EntityFramework2.1.3

 2,添加Module类

namespace Demo.EntityFramework
{
    [DependsOn(typeof(AbpEntityFrameworkModule),typeof(DemoCoreModule))]
    public class DemoDataModule:AbpModule
    {
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
        }
    }
}

 四、Demo.Application

 1,NuGet安装Abp.AutoMapper2.1.3

 2,添加Module类

namespace Demo.Application
{
    [DependsOn(typeof(AbpAutoMapperModule), typeof(DemoCoreModule))]
    public class DemoApplicationModule:AbpModule
    {
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
        }
    }
}

五、Demo.WebApi

 1,NuGet安装Abp.Web.Api2.1.3

 2,添加Module类

namespace Demo.WebApi
{
    [DependsOn(typeof(AbpWebApiModule),typeof(DemoApplicationModule))]
    public class DemoWebApiModule:AbpModule
    {
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

            Configuration.Modules.AbpWebApi().DynamicApiControllerBuilder.ForAll<IApplicationService>(typeof(DemoApplicationModule).Assembly,"app").Build();
        }
    }
}

六、Demo.Web

 1,NuGet安装

Abp.Web.Mvc2.1.3

Abp.Web.Api2.1.3

 2,添加Module类

namespace Demo.Web.App_Start
{

    [DependsOn(typeof(AbpWebMvcModule), typeof(DemoWebApiModule), typeof(DemoDataModule))]
    public class DemoWebModule:AbpModule
    {
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
}

3,修改Global.asax类

namespace Demo.Web
{
    public class MvcApplication : AbpWebApplication<DemoWebModule>
    {
        protected override void Application_Start(object sender, EventArgs e)
        {
            base.Application_Start(sender, e);
        }
    }
}

4,修改RouteConfig.cs

namespace Demo.Web
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            
            routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = UrlParameter.Optional }
            );

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
}

 5,修改web.config连接字符串

<add name="Default" connectionString="Server=localhost; Database=demo; Trusted_Connection=True;" providerName="System.Data.SqlClient" />

demo下载:http://pan.baidu.com/s/1boSQwSv

原文地址:https://www.cnblogs.com/zd1994/p/7525095.html