Guest User

Untitled

a guest
May 27th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using Microsoft.AspNetCore.Builder;
  4. using Microsoft.AspNetCore.Hosting;
  5. using Microsoft.AspNetCore.Identity;
  6. using Microsoft.AspNetCore.Localization;
  7. using Microsoft.AspNetCore.SpaServices.Webpack;
  8. using Microsoft.EntityFrameworkCore;
  9. using Microsoft.Extensions.Configuration;
  10. using Microsoft.Extensions.DependencyInjection;
  11. using Microsoft.Extensions.Options;
  12. using Autofac;
  13. using Autofac.Extensions.DependencyInjection;
  14.  
  15. namespace Web
  16. {
  17. public class Startup
  18. {
  19. public Startup(IConfiguration configuration)
  20. {
  21. Configuration = configuration;
  22. }
  23.  
  24. public IConfiguration Configuration { get; }
  25. public IContainer AppContainer { get; private set; }
  26.  
  27. public IServiceProvider ConfigureServices(IServiceCollection services)
  28. {
  29. services.AddDbContext<Data.Ef.AppDbContext>(options =>
  30. //options.UseInMemoryDatabase("foo")
  31. options.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=foo;Trusted_Connection=True;MultipleActiveResultSets=true")
  32. );
  33.  
  34. services.AddIdentity<Domain.Identity.User, Domain.Identity.Role>()
  35. .AddEntityFrameworkStores<Data.Ef.AppDbContext>()
  36. .AddDefaultTokenProviders();
  37.  
  38. services.AddAuthentication().AddGoogle(googleOptions =>
  39. {
  40. googleOptions.ClientId = Configuration["Authentication:Google:ClientId"];
  41. googleOptions.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
  42. });
  43.  
  44. services.AddLocalization(options => options.ResourcesPath = "Resources");
  45. services.Configure<RequestLocalizationOptions>(options =>
  46. {
  47. var supportedCultures = new[]
  48. {
  49. new CultureInfo("en"),
  50. new CultureInfo("en-US"),
  51. new CultureInfo("fr"),
  52. new CultureInfo("fr-FR"),
  53. };
  54. options.DefaultRequestCulture = new RequestCulture("en");
  55. options.SupportedCultures = supportedCultures;
  56. options.SupportedUICultures = supportedCultures;
  57. });
  58.  
  59. services.AddMvc()
  60. .AddViewLocalization()
  61. .AddDataAnnotationsLocalization();
  62.  
  63. var containerBuilder = new ContainerBuilder();
  64. containerBuilder.Populate(services);
  65. RegisterModules(containerBuilder);
  66. AppContainer = containerBuilder.Build();
  67. return new AutofacServiceProvider(AppContainer);
  68. }
  69.  
  70. public void Configure(
  71. IApplicationBuilder app,
  72. IHostingEnvironment env,
  73. IApplicationLifetime appLifetime)
  74. {
  75. app.UseRequestLocalization(app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>().Value);
  76.  
  77. if (env.IsDevelopment())
  78. {
  79. app.UseBrowserLink();
  80. app.UseDeveloperExceptionPage();
  81. app.UseDatabaseErrorPage();
  82. app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
  83. HotModuleReplacement = true,
  84. });
  85. }
  86. else
  87. {
  88. app.UseExceptionHandler();
  89. }
  90.  
  91. app.UseStaticFiles();
  92.  
  93. app.UseAuthentication();
  94.  
  95. app.UseMvc(routes =>
  96. {
  97. routes.MapRoute(
  98. name: "default",
  99. template: "{controller=Home}/{action=Index}/{id?}");
  100. });
  101.  
  102. appLifetime.ApplicationStopped.Register(() => AppContainer.Dispose());
  103. }
  104.  
  105. private static void RegisterModules(ContainerBuilder containerBuilder)
  106. {
  107. containerBuilder.RegisterModule<Data.Ef.RegistryModule>();
  108. }
  109. }
  110. }
Add Comment
Please, Sign In to add comment