mirror of https://github.com/abpframework/abp.git
csharpabpc-sharpframeworkblazoraspnet-coredotnet-coreaspnetcorearchitecturesaasdomain-driven-designangularmulti-tenancy
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.
216 lines
9.5 KiB
216 lines
9.5 KiB
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;
|
|
//<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)
|
|
)]
|
|
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(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<DbConnectionOptions>(options =>
|
|
{
|
|
options.ConnectionStrings.Default = configuration.GetConnectionString("Default");
|
|
});
|
|
//<TEMPLATE-REMOVE IF-NOT='EntityFrameworkCore'>
|
|
|
|
services.Configure<AbpDbContextOptions>(options => { options.UseSqlServer(); });
|
|
//</TEMPLATE-REMOVE>
|
|
}
|
|
|
|
private static void ConfigureAutoMapper(IServiceCollection services)
|
|
{
|
|
services.Configure<AbpAutoMapperOptions>(options =>
|
|
{
|
|
options.AddProfile<MyProjectNameWebAutoMapperProfile>();
|
|
});
|
|
}
|
|
|
|
private static void ConfigureVirtualFileSystem(IServiceCollection services, IHostingEnvironment hostingEnvironment)
|
|
{
|
|
if (hostingEnvironment.IsDevelopment())
|
|
{
|
|
services.Configure<VirtualFileSystemOptions>(options =>
|
|
{
|
|
options.FileSets.ReplaceEmbeddedByPyhsical<MyProjectNameDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}MyCompanyName.MyProjectName.Domain", Path.DirectorySeparatorChar)));
|
|
//<TEMPLATE-REMOVE>
|
|
options.FileSets.ReplaceEmbeddedByPyhsical<AbpUiModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}framework{0}src{0}Volo.Abp.UI", Path.DirectorySeparatorChar)));
|
|
options.FileSets.ReplaceEmbeddedByPyhsical<AbpAspNetCoreMvcUiModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}..{0}..{0}framework{0}src{0}Volo.Abp.AspNetCore.Mvc.UI", Path.DirectorySeparatorChar)));
|
|
options.FileSets.ReplaceEmbeddedByPyhsical<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.ReplaceEmbeddedByPyhsical<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.ReplaceEmbeddedByPyhsical<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.ReplaceEmbeddedByPyhsical<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.ReplaceEmbeddedByPyhsical<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.ReplaceEmbeddedByPyhsical<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 static void ConfigureLocalizationServices(IServiceCollection services)
|
|
{
|
|
services.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"));
|
|
});
|
|
}
|
|
|
|
private static void ConfigureNavigationServices(IServiceCollection services)
|
|
{
|
|
services.Configure<NavigationOptions>(options =>
|
|
{
|
|
options.MenuContributors.Add(new MyProjectNameMenuContributor());
|
|
});
|
|
}
|
|
|
|
private static void ConfigureAutoApiControllers(IServiceCollection services)
|
|
{
|
|
services.Configure<AbpAspNetCoreMvcOptions>(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<IIdentityDataSeeder>()
|
|
.SeedAsync(
|
|
"1q2w3E*",
|
|
IdentityPermissions.GetAll()
|
|
.Union(MyProjectNamePermissions.GetAll())
|
|
);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|