mirror of https://github.com/abpframework/abp
				
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							215 lines
						
					
					
						
							9.0 KiB
						
					
					
				
			
		
		
	
	
							215 lines
						
					
					
						
							9.0 KiB
						
					
					
				| using System.IO;
 | |
| using System.Linq;
 | |
| using Localization.Resources.AbpUi;
 | |
| using Microsoft.AspNetCore.Builder;
 | |
| using Microsoft.AspNetCore.Hosting;
 | |
| using Microsoft.Extensions.DependencyInjection;
 | |
| using MyCompanyName.MyProjectName.EntityFrameworkCore;
 | |
| using MyCompanyName.MyProjectName.Localization.MyProjectName;
 | |
| using MyCompanyName.MyProjectName.Menus;
 | |
| using MyCompanyName.MyProjectName.Permissions;
 | |
| using Swashbuckle.AspNetCore.Swagger;
 | |
| using Volo.Abp;
 | |
| using Volo.Abp.Account.Web;
 | |
| using Volo.Abp.AspNetCore.Mvc;
 | |
| using Volo.Abp.AspNetCore.Mvc.Localization;
 | |
| using Volo.Abp.AspNetCore.Mvc.UI;
 | |
| using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap;
 | |
| using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic;
 | |
| using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
 | |
| using Volo.Abp.Authorization.Permissions;
 | |
| using Volo.Abp.Autofac;
 | |
| using Volo.Abp.AutoMapper;
 | |
| using Volo.Abp.Data;
 | |
| using Volo.Abp.Identity;
 | |
| using Volo.Abp.Identity.Web;
 | |
| using Volo.Abp.Localization;
 | |
| using Volo.Abp.Localization.Resources.AbpValidation;
 | |
| using Volo.Abp.Modularity;
 | |
| using Volo.Abp.PermissionManagement.Web;
 | |
| using Volo.Abp.Threading;
 | |
| using Volo.Abp.UI;
 | |
| using Volo.Abp.UI.Navigation;
 | |
| using Volo.Abp.VirtualFileSystem;
 | |
| using Volo.Abp.PermissionManagement;
 | |
| using Volo.Abp.TenantManagement.Web;
 | |
| //<TEMPLATE-REMOVE IF-NOT='EntityFrameworkCore'>
 | |
| using Volo.Abp.EntityFrameworkCore;
 | |
| //</TEMPLATE-REMOVE>
 | |
| 
 | |
| namespace MyCompanyName.MyProjectName
 | |
| {
 | |
|     [DependsOn(
 | |
|         typeof(MyProjectNameApplicationModule),
 | |
|         typeof(MyProjectNameEntityFrameworkCoreModule),
 | |
|         typeof(AbpAutofacModule),
 | |
|         typeof(AbpIdentityWebModule),
 | |
|         typeof(AbpAccountWebModule),
 | |
|         typeof(AbpAspNetCoreMvcUiBasicThemeModule),
 | |
|         typeof(AbpTenantManagementWebModule)
 | |
|         )]
 | |
|     public class MyProjectNameWebModule : AbpModule
 | |
|     {
 | |
|         public override void PreConfigureServices(ServiceConfigurationContext context)
 | |
|         {
 | |
|             context.Services.PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options =>
 | |
|             {
 | |
|                 options.AddAssemblyResource(
 | |
|                     typeof(MyProjectNameResource),
 | |
|                     typeof(MyProjectNameDomainModule).Assembly,
 | |
|                     typeof(MyProjectNameApplicationModule).Assembly,
 | |
|                     typeof(MyProjectNameWebModule).Assembly
 | |
|                 );
 | |
|             });
 | |
|         }
 | |
| 
 | |
|         public override void ConfigureServices(ServiceConfigurationContext context)
 | |
|         {
 | |
|             var hostingEnvironment = context.Services.GetHostingEnvironment();
 | |
|             var configuration = context.Services.GetConfiguration();
 | |
| 
 | |
|             ConfigureDatabaseServices();
 | |
|             ConfigureAutoMapper();
 | |
|             ConfigureVirtualFileSystem(hostingEnvironment);
 | |
|             ConfigureLocalizationServices();
 | |
|             ConfigureNavigationServices();
 | |
|             ConfigureAutoApiControllers();
 | |
|             ConfigureSwaggerServices(context.Services);
 | |
|         }
 | |
| 
 | |
|         private void ConfigureDatabaseServices()
 | |
|         {
 | |
|             //<TEMPLATE-REMOVE IF-NOT='EntityFrameworkCore'>
 | |
|             Configure<AbpDbContextOptions>(options =>
 | |
|             {
 | |
|                 options.UseSqlServer();
 | |
|             });
 | |
|             //</TEMPLATE-REMOVE>
 | |
|         }
 | |
| 
 | |
|         private void ConfigureAutoMapper()
 | |
|         {
 | |
|             Configure<AbpAutoMapperOptions>(options =>
 | |
|             {
 | |
|                 options.AddProfile<MyProjectNameWebAutoMapperProfile>();
 | |
|             });
 | |
|         }
 | |
| 
 | |
|         private void ConfigureVirtualFileSystem(IHostingEnvironment hostingEnvironment)
 | |
|         {
 | |
|             if (hostingEnvironment.IsDevelopment())
 | |
|             {
 | |
|                 Configure<VirtualFileSystemOptions>(options =>
 | |
|                 {
 | |
|                     options.FileSets.ReplaceEmbeddedByPhysical<MyProjectNameDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}MyCompanyName.MyProjectName.Domain", Path.DirectorySeparatorChar)));
 | |
|                     //<TEMPLATE-REMOVE>
 | |
|                     options.FileSets.ReplaceEmbeddedByPhysical<AbpUiModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}framework{0}src{0}Volo.Abp.UI", Path.DirectorySeparatorChar)));
 | |
|                     options.FileSets.ReplaceEmbeddedByPhysical<AbpAspNetCoreMvcUiModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}framework{0}src{0}Volo.Abp.AspNetCore.Mvc.UI", Path.DirectorySeparatorChar)));
 | |
|                     options.FileSets.ReplaceEmbeddedByPhysical<AbpAspNetCoreMvcUiBootstrapModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}framework{0}src{0}Volo.Abp.AspNetCore.Mvc.UI.Bootstrap", Path.DirectorySeparatorChar)));
 | |
|                     options.FileSets.ReplaceEmbeddedByPhysical<AbpAspNetCoreMvcUiThemeSharedModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}framework{0}src{0}Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared", Path.DirectorySeparatorChar)));
 | |
|                     options.FileSets.ReplaceEmbeddedByPhysical<AbpAspNetCoreMvcUiBasicThemeModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}framework{0}src{0}Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic", Path.DirectorySeparatorChar)));
 | |
|                     options.FileSets.ReplaceEmbeddedByPhysical<AbpPermissionManagementWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}modules{0}permission-management{0}src{0}Volo.Abp.PermissionManagement.Web", Path.DirectorySeparatorChar)));
 | |
|                     options.FileSets.ReplaceEmbeddedByPhysical<AbpIdentityWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}modules{0}identity{0}src{0}Volo.Abp.Identity.Web", Path.DirectorySeparatorChar)));
 | |
|                     options.FileSets.ReplaceEmbeddedByPhysical<AbpAccountWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}modules{0}account{0}src{0}Volo.Abp.Account.Web", Path.DirectorySeparatorChar)));
 | |
| 					//</TEMPLATE-REMOVE>
 | |
|                 });
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         private void ConfigureLocalizationServices()
 | |
|         {
 | |
|             Configure<AbpLocalizationOptions>(options =>
 | |
|             {
 | |
|                 options.Resources
 | |
|                     .Get<MyProjectNameResource>()
 | |
|                     .AddBaseTypes(
 | |
|                         typeof(AbpValidationResource),
 | |
|                         typeof(AbpUiResource)
 | |
|                     );
 | |
| 
 | |
|                 options.Languages.Add(new LanguageInfo("en", "en", "English"));
 | |
|                 options.Languages.Add(new LanguageInfo("pt-BR", "pt-BR", "Português"));
 | |
|                 options.Languages.Add(new LanguageInfo("tr", "tr", "Türkçe"));
 | |
|                 options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
 | |
|             });
 | |
|         }
 | |
| 
 | |
|         private void ConfigureNavigationServices()
 | |
|         {
 | |
|             Configure<NavigationOptions>(options =>
 | |
|             {
 | |
|                 options.MenuContributors.Add(new MyProjectNameMenuContributor());
 | |
|             });
 | |
|         }
 | |
| 
 | |
|         private void ConfigureAutoApiControllers()
 | |
|         {
 | |
|             Configure<AbpAspNetCoreMvcOptions>(options =>
 | |
|             {
 | |
|                 options.ConventionalControllers.Create(typeof(MyProjectNameApplicationModule).Assembly);
 | |
|             });
 | |
|         }
 | |
| 
 | |
|         private void ConfigureSwaggerServices(IServiceCollection services)
 | |
|         {
 | |
|             services.AddSwaggerGen(
 | |
|                 options =>
 | |
|                 {
 | |
|                     options.SwaggerDoc("v1", new Info { Title = "MyProjectName API", Version = "v1" });
 | |
|                     options.DocInclusionPredicate((docName, description) => true);
 | |
|                     options.CustomSchemaIds(type => type.FullName);
 | |
|                 });
 | |
|         }
 | |
| 
 | |
|         public override void OnApplicationInitialization(ApplicationInitializationContext context)
 | |
|         {
 | |
|             var app = context.GetApplicationBuilder();
 | |
|             var env = context.GetEnvironment();
 | |
| 
 | |
|             if (env.IsDevelopment())
 | |
|             {
 | |
|                 app.UseDeveloperExceptionPage();
 | |
|             }
 | |
|             else
 | |
|             {
 | |
|                 app.UseErrorPage();
 | |
|             }
 | |
| 
 | |
|             app.UseVirtualFiles();
 | |
|             app.UseAuthentication();
 | |
| 
 | |
|             if (MyProjectNameConsts.IsMultiTenancyEnabled)
 | |
|             {
 | |
|                 app.UseMultiTenancy();
 | |
|             }
 | |
| 
 | |
|             app.UseAbpRequestLocalization();
 | |
| 
 | |
|             app.UseSwagger();
 | |
|             app.UseSwaggerUI(options =>
 | |
|             {
 | |
|                 options.SwaggerEndpoint("/swagger/v1/swagger.json", "MyProjectName API");
 | |
|             });
 | |
| 
 | |
|             app.UseAuditing();
 | |
| 
 | |
|             app.UseMvcWithDefaultRouteAndArea();
 | |
| 
 | |
|             SeedDatabase(context);
 | |
|         }
 | |
| 
 | |
|         private static void SeedDatabase(ApplicationInitializationContext context)
 | |
|         {
 | |
|             using (var scope = context.ServiceProvider.CreateScope())
 | |
|             {
 | |
|                 AsyncHelper.RunSync(async () =>
 | |
|                 {
 | |
|                     await scope.ServiceProvider
 | |
|                         .GetRequiredService<IDataSeeder>()
 | |
|                         .SeedAsync();
 | |
|                 });
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| }
 |