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.
193 lines
7.4 KiB
193 lines
7.4 KiB
//#define MONGODB
|
|
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Options;
|
|
using Microsoft.OpenApi.Models;
|
|
using Swashbuckle.AspNetCore.Swagger;
|
|
using Volo.Abp;
|
|
using Volo.Abp.Account;
|
|
using Volo.Abp.Account.Web;
|
|
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.AspNetCore.Mvc.UI.Theming;
|
|
using Volo.Abp.Authorization.Permissions;
|
|
using Volo.Abp.Autofac;
|
|
using Volo.Abp.BlobStoring;
|
|
using Volo.Abp.BlobStoring.Database;
|
|
using Volo.Abp.Data;
|
|
using Volo.Abp.EntityFrameworkCore;
|
|
using Volo.Abp.Identity;
|
|
using Volo.Abp.Identity.Web;
|
|
using Volo.Abp.Modularity;
|
|
using Volo.Abp.PermissionManagement;
|
|
using Volo.Abp.PermissionManagement.HttpApi;
|
|
using Volo.Abp.PermissionManagement.Identity;
|
|
using Volo.Abp.Threading;
|
|
using Volo.Abp.UI;
|
|
using Volo.Abp.VirtualFileSystem;
|
|
using Volo.Blogging;
|
|
using Volo.Blogging.Admin;
|
|
using Volo.Blogging.Files;
|
|
using Volo.BloggingTestApp.EntityFrameworkCore;
|
|
|
|
namespace Volo.BloggingTestApp
|
|
{
|
|
[DependsOn(
|
|
typeof(BloggingWebModule),
|
|
typeof(BloggingApplicationModule),
|
|
typeof(BloggingHttpApiModule),
|
|
typeof(BloggingAdminWebModule),
|
|
typeof(BloggingAdminHttpApiModule),
|
|
typeof(BloggingAdminApplicationModule),
|
|
#if MONGODB
|
|
typeof(BloggingTestAppMongoDbModule),
|
|
#else
|
|
typeof(BloggingTestAppEntityFrameworkCoreModule),
|
|
#endif
|
|
typeof(AbpAccountWebModule),
|
|
typeof(AbpAccountHttpApiModule),
|
|
typeof(AbpAccountApplicationModule),
|
|
typeof(AbpIdentityWebModule),
|
|
typeof(AbpIdentityHttpApiModule),
|
|
typeof(AbpIdentityApplicationModule),
|
|
typeof(AbpPermissionManagementDomainIdentityModule),
|
|
typeof(AbpPermissionManagementApplicationModule),
|
|
typeof(AbpPermissionManagementHttpApiModule),
|
|
typeof(BlobStoringDatabaseDomainModule),
|
|
typeof(AbpAutofacModule),
|
|
typeof(AbpAspNetCoreMvcUiBasicThemeModule)
|
|
)]
|
|
public class BloggingTestAppModule : AbpModule
|
|
{
|
|
public override void ConfigureServices(ServiceConfigurationContext context)
|
|
{
|
|
var hostingEnvironment = context.Services.GetHostingEnvironment();
|
|
var configuration = context.Services.GetConfiguration();
|
|
|
|
Configure<BloggingUrlOptions>(options =>
|
|
{
|
|
options.RoutePrefix = null;
|
|
});
|
|
|
|
Configure<AbpDbConnectionOptions>(options =>
|
|
{
|
|
#if MONGODB
|
|
const string connStringName = "MongoDb";
|
|
#else
|
|
const string connStringName = "SqlServer";
|
|
#endif
|
|
options.ConnectionStrings.Default = configuration.GetConnectionString(connStringName);
|
|
});
|
|
|
|
#if !MONGODB
|
|
Configure<AbpDbContextOptions>(options =>
|
|
{
|
|
options.UseSqlServer();
|
|
});
|
|
#endif
|
|
if (hostingEnvironment.IsDevelopment())
|
|
{
|
|
Configure<AbpVirtualFileSystemOptions>(options =>
|
|
{
|
|
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}modules{0}basic-theme{0}src{0}Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic", Path.DirectorySeparatorChar)));
|
|
options.FileSets.ReplaceEmbeddedByPhysical<BloggingDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Volo.Blogging.Domain", Path.DirectorySeparatorChar)));
|
|
options.FileSets.ReplaceEmbeddedByPhysical<BloggingWebModule>(Path.Combine(hostingEnvironment.ContentRootPath, string.Format("..{0}..{0}src{0}Volo.Blogging.Web", Path.DirectorySeparatorChar)));
|
|
});
|
|
}
|
|
|
|
context.Services.AddSwaggerGen(
|
|
options =>
|
|
{
|
|
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Blogging API", Version = "v1" });
|
|
options.DocInclusionPredicate((docName, description) => true);
|
|
options.CustomSchemaIds(type => type.FullName);
|
|
});
|
|
|
|
var cultures = new List<CultureInfo>
|
|
{
|
|
new CultureInfo("cs"),
|
|
new CultureInfo("en"),
|
|
new CultureInfo("tr"),
|
|
new CultureInfo("zh-Hans")
|
|
};
|
|
|
|
Configure<RequestLocalizationOptions>(options =>
|
|
{
|
|
options.DefaultRequestCulture = new RequestCulture("en");
|
|
options.SupportedCultures = cultures;
|
|
options.SupportedUICultures = cultures;
|
|
});
|
|
|
|
Configure<AbpThemingOptions>(options =>
|
|
{
|
|
options.DefaultThemeName = BasicTheme.Name;
|
|
});
|
|
|
|
Configure<AbpBlobStoringOptions>(options =>
|
|
{
|
|
options.Containers.ConfigureDefault(container =>
|
|
{
|
|
container.UseDatabase();
|
|
});
|
|
});
|
|
}
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context)
|
|
{
|
|
var app = context.GetApplicationBuilder();
|
|
|
|
if (context.GetEnvironment().IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseErrorPage();
|
|
}
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(options =>
|
|
{
|
|
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Support APP API");
|
|
});
|
|
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
|
|
app.UseAbpRequestLocalization();
|
|
|
|
app.UseConfiguredEndpoints();
|
|
|
|
|
|
using (var scope = context.ServiceProvider.CreateScope())
|
|
{
|
|
AsyncHelper.RunSync(async () =>
|
|
{
|
|
await scope.ServiceProvider
|
|
.GetRequiredService<IDataSeeder>()
|
|
.SeedAsync();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|