public void ConfigureServices(IServiceCollection services) { var section = Configuration.GetSection("Blogifier"); services.AddAppSettings<AppItem>(section); //if (section.GetValue<string>("DbProvider") == "SqlServer") //{ AppSettings.DbOptions = options => options.UseSqlServer(section.GetValue<string>("ConnString")); //} //else if (section.GetValue<string>("DbProvider") == "MySql") //{ // AppSettings.DbOptions = options => options.UseMySql(section.GetValue<string>("ConnString")); //} //else //{ // AppSettings.DbOptions = options => options.UseSqlite(section.GetValue<string>("ConnString")); //} services.AddDbContext<AppDbContext>(AppSettings.DbOptions, ServiceLifetime.Transient); //services.AddDbContext<AppDbContext>(options => //{ // //options.UseSqlServer(Configuration.GetConnectionString("BlogCristianoConnection"), // // b => b.MigrationsAssembly("App")); // // Configure the context to use Microsoft SQL Server. // options.UseSqlServer(Configuration.GetConnectionString("BlogCristianoConnection"), // b => b.MigrationsAssembly("Core")); //}); services.AddIdentity<AppUser, IdentityRole>(options => { options.Password.RequireDigit = false; options.Password.RequiredLength = 4; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; options.User.AllowedUserNameCharacters = null; }) .AddEntityFrameworkStores<AppDbContext>() .AddDefaultTokenProviders(); services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true)); services.AddJsonLocalization(); services.Configure<RequestLocalizationOptions>(options => { var supportedCultures = new[] { new CultureInfo("en-US"), new CultureInfo("ru-RU"), new CultureInfo("zh-cn"), new CultureInfo("zh-tw") }; options.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US"); options.SupportedCultures = supportedCultures; options.SupportedUICultures = supportedCultures; }); services.AddRouting(options => options.LowercaseUrls = true); services.AddMvc() .AddViewLocalization() .ConfigureApplicationPartManager(p => { foreach (var assembly in AppConfig.GetAssemblies()) { p.ApplicationParts.Add(new AssemblyPart(assembly)); } }) .AddRazorPagesOptions(options => { options.Conventions.AuthorizeFolder("/Admin"); }) .AddApplicationPart(typeof(Core.Api.AuthorsController).GetTypeInfo().Assembly).AddControllersAsServices() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddAppServices(); }
public void ConfigureServices(IServiceCollection services) { var section = Configuration.GetSection("Blogifier"); services.AddAppSettings <AppItem>(section); if (section.GetValue <string>("DbProvider") == "SqlServer") { AppSettings.DbOptions = options => options.UseSqlServer(section.GetValue <string>("ConnString")); } else if (section.GetValue <string>("DbProvider") == "MySql") { AppSettings.DbOptions = options => options.UseMySql(section.GetValue <string>("ConnString")); } else { AppSettings.DbOptions = options => options.UseSqlite(section.GetValue <string>("ConnString")); } services.AddDbContext <AppDbContext>(AppSettings.DbOptions, ServiceLifetime.Transient); services.AddIdentity <AppUser, IdentityRole>(options => { options.Password.RequireDigit = false; options.Password.RequiredLength = 4; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; options.User.AllowedUserNameCharacters = null; }) .AddEntityFrameworkStores <AppDbContext>() .AddDefaultTokenProviders(); services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true)); services.AddJsonLocalization(); services.Configure <RequestLocalizationOptions>(options => { var supportedCultures = new[] { new CultureInfo("en-US"), new CultureInfo("es-ES"), new CultureInfo("pt-BR"), new CultureInfo("ru-RU"), new CultureInfo("zh-cn"), new CultureInfo("zh-tw") }; options.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US"); options.SupportedCultures = supportedCultures; options.SupportedUICultures = supportedCultures; }); services.AddRouting(options => options.LowercaseUrls = true); services.AddMvc() .AddViewLocalization() .ConfigureApplicationPartManager(p => { foreach (var assembly in AppConfig.GetAssemblies()) { p.ApplicationParts.Add(new AssemblyPart(assembly)); } }) .AddRazorPagesOptions(options => { options.Conventions.AuthorizeFolder("/Admin"); }) .AddApplicationPart(typeof(Core.Api.AuthorsController).GetTypeInfo().Assembly).AddControllersAsServices() .SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddSwaggerGen(setupAction => { setupAction.SwaggerDoc("spec", new Microsoft.OpenApi.Models.OpenApiInfo() { Title = "Blogifier API", Version = "1" }); setupAction.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "CoreAPI.xml")); }); services.AddSpaStaticFiles(configuration => { configuration.RootPath = "wwwroot/themes/_active"; }); services.AddCors(c => { c.AddPolicy("AllowOrigin", options => options .AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod() ); }); services.AddAppServices(); }
public void ConfigureServices(IServiceCollection services) { var section = Configuration.GetSection("Blogifier"); services.AddAppSettings <AppItem>(section); if (section.GetValue <string>("DbProvider") == "SqlServer") { //AppSettings.DbOptions = options => options.UseSqlServer(section.GetValue<string>("ConnString")); throw new NotSupportedException(); } else if (section.GetValue <string>("DbProvider") == "MySql") { AppSettings.DbOptions = options => options.UseMySql(section.GetValue <string>("ConnString")); } else { AppSettings.DbOptions = options => options.UseSqlite(section.GetValue <string>("ConnString")); } services .AddDbContext <AppDbContext>(AppSettings.DbOptions, ServiceLifetime.Transient); services.AddIdentity <AppUser, IdentityRole>(options => { options.Password.RequireDigit = false; options.Password.RequiredLength = 4; options.Password.RequireNonAlphanumeric = false; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; options.User.AllowedUserNameCharacters = null; }) .AddEntityFrameworkStores <AppDbContext>() .AddDefaultTokenProviders(); services.AddLogging(loggingBuilder => loggingBuilder.AddSerilog(dispose: true)); services.AddJsonLocalization(options => { //"Resources" by default //options.ResourcesPath; }); services.ConfigureLocalizationOptions(); services.AddRouting(options => { options.LowercaseUrls = true; options.AppendTrailingSlash = true; }); services.AddRazorPages(); services.AddMvc() .AddViewLocalization() .ConfigureApplicationPartManager(p => { foreach (var assembly in AppConfig.GetAssemblies()) { p.ApplicationParts.Add(new AssemblyPart(assembly)); } }) .AddRazorPagesOptions(options => { options.Conventions.AuthorizeFolder("/Admin"); }) .AddApplicationPart(typeof(Core.Api.AuthorsController).GetTypeInfo().Assembly) .AddControllersAsServices() .SetCompatibilityVersion(CompatibilityVersion.Version_3_0); services.AddSwaggerGen(setupAction => { setupAction.SwaggerDoc("spec", new Microsoft.OpenApi.Models.OpenApiInfo() { Title = "Blogifier API", Version = "1" }); setupAction.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "CoreAPI.xml")); }); services.AddSpaStaticFiles(configuration => { configuration.RootPath = "Custom/themes/custom"; }); services.AddCors(c => { c.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin()); }); services.AddAppServices(); }