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(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(); } private static void ConfigureAutoMapper(IServiceCollection services) { services.Configure(options => { options.AddProfile(validate: true); }); } private static void ConfigureAutoApiControllers(IServiceCollection services) { services.Configure(options => { options.ConventionalControllers.Create(typeof(BookStoreApplicationModule).Assembly); }); } 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 ConfigureVirtualFileSystem(IServiceCollection services, IHostingEnvironment hostingEnvironment) { if (hostingEnvironment.IsDevelopment()) { services.Configure(options => { options.FileSets.ReplaceEmbeddedByPyhsical(Path.Combine(hostingEnvironment.ContentRootPath, "..\\Acme.BookStore.Domain")); }); } } private static void ConfigureLocalizationServices(IServiceCollection services) { var cultures = new List {new CultureInfo("en"), new CultureInfo("tr")}; services.Configure(options => { options.DefaultRequestCulture = new RequestCulture("en"); options.SupportedCultures = cultures; options.SupportedUICultures = cultures; }); services.Configure(options => { options.Resources .Get() .AddBaseTypes( typeof(AbpValidationResource), typeof(AbpUiResource) ); }); } private static void ConfigureNavigationServices(IServiceCollection services) { services.Configure(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>().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() .SeedAsync( "1q2w3E*", IdentityPermissions.GetAll() //.Union(BookStorePermissions.GetAll()) ); }); } } }