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.
143 lines
5.6 KiB
143 lines
5.6 KiB
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using MyCompanyName.MyProjectName.EntityFrameworkCore;
|
|
using Swashbuckle.AspNetCore.Swagger;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Account.Web;
|
|
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.Data;
|
|
using Volo.Abp.EntityFrameworkCore;
|
|
using Volo.Abp.EntityFrameworkCore.SqlServer;
|
|
using Volo.Abp.Identity;
|
|
using Volo.Abp.Identity.EntityFrameworkCore;
|
|
using Volo.Abp.Identity.Web;
|
|
using Volo.Abp.Localization;
|
|
using Volo.Abp.Modularity;
|
|
using Volo.Abp.PermissionManagement;
|
|
using Volo.Abp.PermissionManagement.EntityFrameworkCore;
|
|
using Volo.Abp.PermissionManagement.Identity;
|
|
using Volo.Abp.SettingManagement.EntityFrameworkCore;
|
|
using Volo.Abp.Threading;
|
|
using Volo.Abp.VirtualFileSystem;
|
|
|
|
namespace MyCompanyName.MyProjectName.DemoApp
|
|
{
|
|
[DependsOn(
|
|
typeof(MyProjectNameWebModule),
|
|
typeof(MyProjectNameApplicationModule),
|
|
typeof(MyProjectNameEntityFrameworkCoreModule),
|
|
|
|
typeof(AbpPermissionManagementEntityFrameworkCoreModule),
|
|
typeof(AbpSettingManagementEntityFrameworkCoreModule),
|
|
typeof(AbpIdentityEntityFrameworkCoreModule),
|
|
typeof(AbpEntityFrameworkCoreSqlServerModule),
|
|
|
|
typeof(AbpAccountWebModule),
|
|
typeof(AbpIdentityWebModule),
|
|
typeof(AbpIdentityApplicationModule),
|
|
typeof(AbpPermissionManagementApplicationModule),
|
|
typeof(AbpPermissionManagementDomainIdentityModule),
|
|
typeof(AbpAutofacModule),
|
|
typeof(AbpAspNetCoreMvcUiBasicThemeModule)
|
|
)]
|
|
public class DemoAppModule : AbpModule
|
|
{
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment();
|
|
var configuration = context.Services.BuildConfiguration();
|
|
|
|
Configure<DbConnectionOptions>(options =>
|
|
{
|
|
options.ConnectionStrings.Default = configuration.GetConnectionString("Default");
|
|
});
|
|
|
|
Configure<AbpDbContextOptions>(options =>
|
|
{
|
|
options.UseSqlServer();
|
|
});
|
|
|
|
if (hostingEnvironment.IsDevelopment())
|
|
{
|
|
Configure<VirtualFileSystemOptions>(options =>
|
|
{
|
|
options.FileSets.ReplaceEmbeddedByPhysical<MyProjectNameWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}MyCompanyName.MyProjectName.Web", Path.DirectorySeparatorChar)));
|
|
options.FileSets.ReplaceEmbeddedByPhysical<MyProjectNameDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}MyCompanyName.MyProjectName.Domain", Path.DirectorySeparatorChar)));
|
|
options.FileSets.ReplaceEmbeddedByPhysical<MyProjectNameApplicationModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}MyCompanyName.MyProjectName.Application", Path.DirectorySeparatorChar)));
|
|
options.FileSets.ReplaceEmbeddedByPhysical<MyProjectNameApplicationContractsModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}MyCompanyName.MyProjectName.Application.Contracts", Path.DirectorySeparatorChar)));
|
|
});
|
|
}
|
|
|
|
context.Services.AddSwaggerGen(
|
|
options =>
|
|
{
|
|
options.SwaggerDoc("v1", new Info { Title = "MyProjectName API", Version = "v1" });
|
|
options.DocInclusionPredicate((docName, description) => true);
|
|
options.CustomSchemaIds(type => type.FullName);
|
|
});
|
|
|
|
Configure<AbpLocalizationOptions>(options =>
|
|
{
|
|
options.Languages.Add(new LanguageInfo("en", "en", "English"));
|
|
//...add other languages
|
|
});
|
|
}
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
|
{
|
|
var app = context.GetApplicationBuilder();
|
|
|
|
if (context.GetEnvironment().IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseErrorPage();
|
|
}
|
|
|
|
app.UseVirtualFiles();
|
|
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(options =>
|
|
{
|
|
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support APP API");
|
|
});
|
|
|
|
app.UseAuthentication();
|
|
app.UseAbpRequestLocalization();
|
|
app.UseAuditing();
|
|
|
|
|
|
app.UseMvcWithDefaultRouteAndArea();
|
|
|
|
using (var scope = context.ServiceProvider.CreateScope())
|
|
{
|
|
AsyncHelper.RunSync(async () =>
|
|
{
|
|
await scope.ServiceProvider
|
|
.GetRequiredService<IIdentityDataSeeder>()
|
|
.SeedAsync(
|
|
"1q2w3E*"
|
|
);
|
|
|
|
await scope.ServiceProvider
|
|
.GetRequiredService<IPermissionDataSeeder>()
|
|
.SeedAsync(
|
|
RolePermissionValueProvider.ProviderName,
|
|
"admin",
|
|
IdentityPermissions.GetAll().Union(MyProjectNamePermissions.GetAll())
|
|
);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|