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.
201 lines
7.1 KiB
201 lines
7.1 KiB
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using Localization.Resources.AbpUi;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
using Acme.BookStore.EntityFrameworkCore;
|
|
using Acme.BookStore.Localization.BookStore;
|
|
using Acme.BookStore.Menus;
|
|
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.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.EntityFrameworkCore;
|
|
using Volo.Abp.Identity;
|
|
using Volo.Abp.Identity.Localization;
|
|
using Volo.Abp.Identity.Web;
|
|
using Volo.Abp.Localization;
|
|
using Volo.Abp.Localization.Resources.AbpValidation;
|
|
using Volo.Abp.Modularity;
|
|
using Volo.Abp.Threading;
|
|
using Volo.Abp.UI.Navigation;
|
|
using Volo.Abp.VirtualFileSystem;
|
|
|
|
namespace Acme.BookStore
|
|
{
|
|
[DependsOn(
|
|
typeof(BookStoreApplicationModule),
|
|
typeof(BookStoreEntityFrameworkCoreModule),
|
|
typeof(AbpAutofacModule),
|
|
typeof(AbpIdentityWebModule),
|
|
typeof(AbpAccountWebModule),
|
|
typeof(AbpAspNetCoreMvcUiBasicThemeModule)
|
|
)]
|
|
public class BookStoreWebModule : AbpModule
|
|
{
|
|
public override void PreConfigureServices(IServiceCollection services)
|
|
{
|
|
services.PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options =>
|
|
{
|
|
options.AddAssemblyResource(typeof(BookStoreResource), typeof(BookStoreWebModule).Assembly);
|
|
});
|
|
}
|
|
|
|
public override void ConfigureServices(IServiceCollection services)
|
|
{
|
|
var hostingEnvironment = services.GetHostingEnvironment();
|
|
var configuration = services.BuildConfiguration();
|
|
|
|
ConfigureDatabaseServices(services, configuration);
|
|
ConfigureAutoMapper(services);
|
|
ConfigureVirtualFileSystem(services, hostingEnvironment);
|
|
ConfigureLocalizationServices(services);
|
|
ConfigureNavigationServices(services);
|
|
ConfigureAutoApiControllers(services);
|
|
ConfigureSwaggerServices(services);
|
|
|
|
services.AddAssemblyOf<BookStoreWebModule>();
|
|
}
|
|
|
|
private static void ConfigureAutoMapper(IServiceCollection services)
|
|
{
|
|
services.Configure<AbpAutoMapperOptions>(options =>
|
|
{
|
|
options.AddProfile<BookStoreWebAutoMapperProfile>(validate: true);
|
|
});
|
|
}
|
|
|
|
private static void ConfigureAutoApiControllers(IServiceCollection services)
|
|
{
|
|
services.Configure<AbpAspNetCoreMvcOptions>(options =>
|
|
{
|
|
options.ConventionalControllers.Create(typeof(BookStoreApplicationModule).Assembly);
|
|
});
|
|
}
|
|
|
|
private static void ConfigureDatabaseServices(IServiceCollection services, IConfigurationRoot configuration)
|
|
{
|
|
services.Configure<DbConnectionOptions>(options =>
|
|
{
|
|
options.ConnectionStrings.Default = configuration.GetConnectionString("Default");
|
|
});
|
|
|
|
services.Configure<AbpDbContextOptions>(options => { options.UseSqlServer(); });
|
|
}
|
|
|
|
private static void ConfigureVirtualFileSystem(IServiceCollection services, IHostingEnvironment hostingEnvironment)
|
|
{
|
|
if (hostingEnvironment.IsDevelopment())
|
|
{
|
|
services.Configure<VirtualFileSystemOptions>(options =>
|
|
{
|
|
options.FileSets.ReplaceEmbeddedByPyhsical<BookStoreDomainModule>(Path.Combine(hostingEnvironment.ContentRootPath, "..\\Acme.BookStore.Domain"));
|
|
});
|
|
}
|
|
}
|
|
|
|
private static void ConfigureLocalizationServices(IServiceCollection services)
|
|
{
|
|
var cultures = new List<CultureInfo> {new CultureInfo("en"), new CultureInfo("tr")};
|
|
services.Configure<RequestLocalizationOptions>(options =>
|
|
{
|
|
options.DefaultRequestCulture = new RequestCulture("en");
|
|
options.SupportedCultures = cultures;
|
|
options.SupportedUICultures = cultures;
|
|
});
|
|
|
|
services.Configure<AbpLocalizationOptions>(options =>
|
|
{
|
|
options.Resources
|
|
.Get<BookStoreResource>()
|
|
.AddBaseTypes(
|
|
typeof(AbpValidationResource),
|
|
typeof(AbpUiResource)
|
|
);
|
|
});
|
|
}
|
|
|
|
private static void ConfigureNavigationServices(IServiceCollection services)
|
|
{
|
|
services.Configure<NavigationOptions>(options =>
|
|
{
|
|
options.MenuContributors.Add(new BookStoreMenuContributor());
|
|
});
|
|
}
|
|
|
|
private static void ConfigureSwaggerServices(IServiceCollection services)
|
|
{
|
|
services.AddSwaggerGen(
|
|
options =>
|
|
{
|
|
options.SwaggerDoc("v1", new Info { Title = "BookStore 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.UseStaticFiles();
|
|
app.UseVirtualFiles();
|
|
app.UseAuthentication();
|
|
|
|
app.UseRequestLocalization(app.ApplicationServices.GetRequiredService<IOptions<RequestLocalizationOptions>>().Value);
|
|
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI(options =>
|
|
{
|
|
options.SwaggerEndpoint("/swagger/v1/swagger.json", "BookStore API");
|
|
});
|
|
|
|
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(BookStorePermissions.GetAll())
|
|
);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|