PS:中文文档地址
1- 生成项目的方式
1.1- 模板生成地址
1.2-abp cli 命令生成
https://docs.abp.io/zh-Hans/abp/latest/Getting-Started?UI=MVC&DB=EF&Tiered=No
2-项目结构
PS:我是纯手工制作,从空白模板开始的
2.1-结构如下
PS:我不打算用动态API 所以结构做了删减
- GR.CMS.Domain.Shared
我需要审计日志和后台任务功能,所以添加如下引用
Volo.Abp.Validation,
Volo.Abp.AuditLogging.Domain.Shared,
Volo.Abp.BackgroundJobs.Domain.Shared
1 [DependsOn( 2 typeof(AbpAuditLoggingDomainSharedModule), 3 typeof(AbpBackgroundJobsDomainSharedModule) 4 )] 5 public class CMSDomainSharedModule : AbpModule 6 { 7 public override void PreConfigureServices(ServiceConfigurationContext context) 8 { 9 CMSGlobalFeatureConfigurator.Configure(); 10 CMSModuleExtensionConfigurator.Configure(); 11 } 12 13 public override void ConfigureServices(ServiceConfigurationContext context) 14 { 15 Configure<AbpVirtualFileSystemOptions>(options => 16 { 17 options.FileSets.AddEmbedded<CMSDomainSharedModule>(); 18 }); 19 20 Configure<AbpLocalizationOptions>(options => 21 { 22 options.Resources 23 .Add<CMSResource>("en") 24 .AddBaseTypes(typeof(AbpValidationResource)) 25 .AddVirtualJson("/Localization/CMS"); 26 27 options.DefaultResourceType = typeof(CMSResource); 28 }); 29 30 Configure<AbpExceptionLocalizationOptions>(options => 31 { 32 options.MapCodeNamespace("CMS", typeof(CMSResource)); 33 }); 34 } 35 }
其他类都是照着生成的DEMO 扣的
- GR.CMS.Domain
添加如下引用
GR.CMS.Domain.Shared ,
Volo.Abp.AuditLogging.Domain,
Volo.Abp.BackgroundJobs.Domain
PS:暂时我不太想要多租户,所以注释了相关配置
1 [DependsOn( 2 typeof(CMSDomainSharedModule), 3 typeof(AbpAuditLoggingDomainModule), 4 typeof(AbpBackgroundJobsDomainModule) 5 )] 6 public class CMSDomainModule : AbpModule 7 { 8 public override void ConfigureServices(ServiceConfigurationContext context) 9 { 10 //Configure<AbpMultiTenancyOptions>(options => 11 //{ 12 // options.IsEnabled = MultiTenancyConsts.IsEnabled; 13 //}); 14 15 #if DEBUG 16 //context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>()); 17 #endif 18 } 19 }
- GR.CMS.Application.Contracts
添加如下引用
GR.CMS.Domain.Shared ,
1 [DependsOn( 2 typeof(CMSDomainSharedModule) 3 )] 4 public class CMSApplicationContractsModule : AbpModule 5 { 6 }
- GR.CMS.Application
添加如下引用
GR.CMS.Domain.Shared ,
GR.CMS.Application.Contracts
1 [DependsOn( 2 typeof(CMSApplicationContractsModule), 3 typeof(CMSDomainModule) 4 )] 5 public class CMSApplicationModule : AbpModule 6 { 7 }
- GR.CMS.EntityFrameworkCore
添加如下引用
GR.CMS.Domain,
Volo.Abp.EntityFrameworkCore.MySQL,
Volo.Abp.AuditLogging.EntityFrameworkCore,
Volo.Abp.BackgroundJobs.EntityFrameworkCore
1 [DependsOn( 2 typeof(CMSDomainModule), 3 typeof(AbpEntityFrameworkCoreMySQLModule), 4 typeof(AbpAuditLoggingEntityFrameworkCoreModule), 5 typeof(AbpBackgroundJobsEntityFrameworkCoreModule) 6 )] 7 public class CMSEntityFrameworkCoreModule : AbpModule 8 { 9 public override void PreConfigureServices(ServiceConfigurationContext context) 10 { 11 CMSEfCoreEntityExtensionMappings.Configure(); 12 } 13 14 public override void ConfigureServices(ServiceConfigurationContext context) 15 { 16 context.Services.AddAbpDbContext<CMSDbContext>(options => 17 { 18 /* Remove "includeAllEntities: true" to create 19 * default repositories only for aggregate roots */ 20 options.AddDefaultRepositories(includeAllEntities: true); 21 }); 22 23 Configure<AbpDbContextOptions>(options => 24 { 25 /* The main point to change your DBMS. 26 * See also CMSMigrationsDbContextFactory for EF Core tooling. */ 27 options.UseMySQL(); 28 }); 29 } 30 }
- GR.CMS.Web
添加如下引用
GR.CMS.Application,
GR.CMS.EntityFrameworkCore,
Volo.Abp.AspNetCore.Mvc,
Volo.Abp.Autofac,
Volo.Abp.BackgroundJobs.EntityFrameworkCore,
Serilog.AspNetCore,
Serilog.Sinks.Async,
Volo.Abp.AspNetCore.Serilog
1 [DependsOn( 2 typeof(CMSApplicationModule), 3 typeof(CMSEntityFrameworkCoreModule), 4 typeof(AbpAspNetCoreMvcModule), 5 typeof(AbpAutofacModule))] 6 public class CMSWebModule : AbpModule 7 { 8 public override void PreConfigureServices(ServiceConfigurationContext context) 9 { 10 context.Services.PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options => 11 { 12 options.AddAssemblyResource( 13 typeof(CMSResource), 14 typeof(CMSDomainModule).Assembly, 15 typeof(CMSDomainSharedModule).Assembly, 16 typeof(CMSApplicationModule).Assembly, 17 typeof(CMSApplicationContractsModule).Assembly, 18 typeof(CMSWebModule).Assembly 19 ); 20 }); 21 } 22 23 public override void ConfigureServices(ServiceConfigurationContext context) 24 { 25 var hostingEnvironment = context.Services.GetHostingEnvironment(); 26 var configuration = context.Services.GetConfiguration(); 27 28 ConfigureUrls(configuration); 29 30 ConfigureAutoMapper(); 31 ConfigureVirtualFileSystem(hostingEnvironment); 32 ConfigureLocalizationServices(); 33 34 ConfigureAutoApiControllers(); 35 36 } 37 38 private void ConfigureUrls(IConfiguration configuration) 39 { 40 Configure<AppUrlOptions>(options => 41 { 42 options.Applications["MVC"].RootUrl = configuration["App:SelfUrl"]; 43 }); 44 } 45 46 47 48 private void ConfigureAutoMapper() 49 { 50 Configure<AbpAutoMapperOptions>(options => 51 { 52 options.AddMaps<CMSWebModule>(); 53 }); 54 } 55 56 private void ConfigureVirtualFileSystem(IWebHostEnvironment hostingEnvironment) 57 { 58 if (hostingEnvironment.IsDevelopment()) 59 { 60 Configure<AbpVirtualFileSystemOptions>(options => 61 { 62 options.FileSets.ReplaceEmbeddedByPhysical<CMSDomainSharedModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}GR.CMS.Domain.Shared")); 63 options.FileSets.ReplaceEmbeddedByPhysical<CMSDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}GR.CMS.Domain")); 64 options.FileSets.ReplaceEmbeddedByPhysical<CMSApplicationContractsModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}GR.CMS.Application.Contracts")); 65 options.FileSets.ReplaceEmbeddedByPhysical<CMSApplicationModule>(Path.Combine(hostingEnvironment.ContentRootPath, $"..{Path.DirectorySeparatorChar}GR.CMS.Application")); 66 options.FileSets.ReplaceEmbeddedByPhysical<CMSWebModule>(hostingEnvironment.ContentRootPath); 67 }); 68 } 69 } 70 71 private void ConfigureLocalizationServices() 72 { 73 Configure<AbpLocalizationOptions>(options => 74 { 75 options.Languages.Add(new LanguageInfo("en", "en", "English")); 76 options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文")); 77 options.Languages.Add(new LanguageInfo("zh-Hant", "zh-Hant", "繁體中文")); 78 }); 79 } 80 81 82 83 private void ConfigureAutoApiControllers() 84 { 85 Configure<AbpAspNetCoreMvcOptions>(options => 86 { 87 options.ConventionalControllers.Create(typeof(CMSApplicationModule).Assembly); 88 }); 89 } 90 91 92 93 public override void OnApplicationInitialization(ApplicationInitializationContext context) 94 { 95 var app = context.GetApplicationBuilder(); 96 var env = context.GetEnvironment(); 97 98 if (env.IsDevelopment()) 99 { 100 app.UseDeveloperExceptionPage(); 101 } 102 103 app.UseAbpRequestLocalization(); 104 105 106 app.UseCorrelationId(); 107 app.UseStaticFiles(); 108 app.UseRouting(); 109 app.UseAuthentication(); 110 111 app.UseUnitOfWork(); 112 113 app.UseAuthorization(); 114 115 app.UseAuditing(); 116 app.UseAbpSerilogEnrichers(); 117 app.UseConfiguredEndpoints(); 118 } 119 }
PS: 这样子,基本的架子就搭建成功了,然后运行的时候因为没有生成相关数据库,所以会有错误日志输出
PS:文档地址