Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Identity;
- using Microsoft.AspNetCore.Localization;
- using Microsoft.AspNetCore.SpaServices.Webpack;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Options;
- using Autofac;
- using Autofac.Extensions.DependencyInjection;
- namespace Web
- {
- public class Startup
- {
- public Startup(IConfiguration configuration)
- {
- Configuration = configuration;
- }
- public IConfiguration Configuration { get; }
- public IContainer AppContainer { get; private set; }
- public IServiceProvider ConfigureServices(IServiceCollection services)
- {
- services.AddDbContext<Data.Ef.AppDbContext>(options =>
- //options.UseInMemoryDatabase("foo")
- options.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=foo;Trusted_Connection=True;MultipleActiveResultSets=true")
- );
- services.AddIdentity<Domain.Identity.User, Domain.Identity.Role>()
- .AddEntityFrameworkStores<Data.Ef.AppDbContext>()
- .AddDefaultTokenProviders();
- services.AddAuthentication().AddGoogle(googleOptions =>
- {
- googleOptions.ClientId = Configuration["Authentication:Google:ClientId"];
- googleOptions.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
- });
- services.AddLocalization(options => options.ResourcesPath = "Resources");
- services.Configure<RequestLocalizationOptions>(options =>
- {
- var supportedCultures = new[]
- {
- new CultureInfo("en"),
- new CultureInfo("en-US"),
- new CultureInfo("fr"),
- new CultureInfo("fr-FR"),
- };
- options.DefaultRequestCulture = new RequestCulture("en");
- options.SupportedCultures = supportedCultures;
- options.SupportedUICultures = supportedCultures;
- });
- services.AddMvc()
- .AddViewLocalization()
- .AddDataAnnotationsLocalization();
- var containerBuilder = new ContainerBuilder();
- containerBuilder.Populate(services);
- RegisterModules(containerBuilder);
- AppContainer = containerBuilder.Build();
- return new AutofacServiceProvider(AppContainer);
- }
- public void Configure(
- IApplicationBuilder app,
- IHostingEnvironment env,
- IApplicationLifetime appLifetime)
- {
- app.UseRequestLocalization(app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>().Value);
- if (env.IsDevelopment())
- {
- app.UseBrowserLink();
- app.UseDeveloperExceptionPage();
- app.UseDatabaseErrorPage();
- app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
- HotModuleReplacement = true,
- });
- }
- else
- {
- app.UseExceptionHandler();
- }
- app.UseStaticFiles();
- app.UseAuthentication();
- app.UseMvc(routes =>
- {
- routes.MapRoute(
- name: "default",
- template: "{controller=Home}/{action=Index}/{id?}");
- });
- appLifetime.ApplicationStopped.Register(() => AppContainer.Dispose());
- }
- private static void RegisterModules(ContainerBuilder containerBuilder)
- {
- containerBuilder.RegisterModule<Data.Ef.RegistryModule>();
- }
- }
- }
Add Comment
Please, Sign In to add comment