using System.IO; using System.Linq; using Localization.Resources.AbpUi; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; 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.Modularity; 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.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.EntityFrameworkCore; // namespace MyCompanyName.MyProjectName { [DependsOn( typeof(MyProjectNameApplicationModule), typeof(MyProjectNameEntityFrameworkCoreModule), typeof(AbpAutofacModule), typeof(AbpIdentityWebModule), typeof(AbpAccountWebModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule) )] public class MyProjectNameWebModule : AbpModule { public override void PreConfigureServices(ServiceConfigurationContext context) { context.Services.PreConfigure(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(context.Services, configuration); ConfigureAutoMapper(context.Services); ConfigureVirtualFileSystem(context.Services, hostingEnvironment); ConfigureLocalizationServices(context.Services); ConfigureNavigationServices(context.Services); ConfigureAutoApiControllers(context.Services); ConfigureSwaggerServices(context.Services); } private static void ConfigureDatabaseServices(IServiceCollection services, IConfigurationRoot configuration) { services.Configure(options => { options.ConnectionStrings.Default = configuration.GetConnectionString("Default"); }); // services.Configure(options => { options.UseSqlServer(); }); // } private static void ConfigureAutoMapper(IServiceCollection services) { services.Configure(options => { options.AddProfile(); }); } private static void ConfigureVirtualFileSystem(IServiceCollection services, IHostingEnvironment hostingEnvironment) { if (hostingEnvironment.IsDevelopment()) { services.Configure(options => { options.FileSets.ReplaceEmbeddedByPyhsical(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}MyCompanyName.MyProjectName.Domain", Path.DirectorySeparatorChar))); // options.FileSets.ReplaceEmbeddedByPyhsical(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}framework{0}src{0}Volo.Abp.UI", Path.DirectorySeparatorChar))); options.FileSets.ReplaceEmbeddedByPyhsical(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}framework{0}src{0}Volo.Abp.AspNetCore.Mvc.UI", Path.DirectorySeparatorChar))); options.FileSets.ReplaceEmbeddedByPyhsical(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}framework{0}src{0}Volo.Abp.AspNetCore.Mvc.UI.Bootstrap", Path.DirectorySeparatorChar))); options.FileSets.ReplaceEmbeddedByPyhsical(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.ReplaceEmbeddedByPyhsical(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.ReplaceEmbeddedByPyhsical(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.ReplaceEmbeddedByPyhsical(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}modules{0}identity{0}src{0}Volo.Abp.Identity.Web", Path.DirectorySeparatorChar))); options.FileSets.ReplaceEmbeddedByPyhsical(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}modules{0}account{0}src{0}Volo.Abp.Account.Web", Path.DirectorySeparatorChar))); // }); } } private static void ConfigureLocalizationServices(IServiceCollection services) { services.Configure(options => { options.Resources .Get() .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")); }); } private static void ConfigureNavigationServices(IServiceCollection services) { services.Configure(options => { options.MenuContributors.Add(new MyProjectNameMenuContributor()); }); } private static void ConfigureAutoApiControllers(IServiceCollection services) { services.Configure(options => { options.ConventionalControllers.Create(typeof(MyProjectNameApplicationModule).Assembly); }); } private static void ConfigureSwaggerServices(IServiceCollection services) { services.AddSwaggerGen( options => { options.SwaggerDoc("v1", new Info { Title = "MyProjectName API", Version = "v1" }); options.DocInclusionPredicate((docName, description) => true); }); } 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(); app.UseAbpRequestLocalization(); app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "MyProjectName API"); }); app.UseAuditing(); app.UseMvc(routes => { routes.MapRoute( name: "defaultWithArea", template: "{area}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); SeedDatabase(context); } private static void SeedDatabase(ApplicationInitializationContext context) { AsyncHelper.RunSync(async () => { await context.ServiceProvider .GetRequiredService() .SeedAsync( "1q2w3E*", IdentityPermissions.GetAll() .Union(MyProjectNamePermissions.GetAll()) ); }); } } }