Startup.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
  8. using Microsoft.EntityFrameworkCore;
  9. using Microsoft.Extensions.Configuration;
  10. using Microsoft.Extensions.DependencyInjection;
  11. using Microsoft.Extensions.Logging;
  12. using Winsoft.GOV.XF.WXCore.Data;
  13. using Winsoft.GOV.XF.WXCore.Models;
  14. using Winsoft.GOV.XF.WXCore.Services;
  15. using Microsoft.AspNetCore.Identity;
  16. namespace Winsoft.GOV.XF.WXCore
  17. {
  18. public class Startup
  19. {
  20. public Startup(IHostingEnvironment env)
  21. {
  22. var builder = new ConfigurationBuilder()
  23. .SetBasePath(env.ContentRootPath)
  24. .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
  25. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
  26. if (env.IsDevelopment())
  27. {
  28. // For more details on using the user secret store see https://go.microsoft.com/fwlink/?LinkID=532709
  29. builder.AddUserSecrets<Startup>();
  30. }
  31. builder.AddEnvironmentVariables();
  32. Configuration = builder.Build();
  33. }
  34. public IConfigurationRoot Configuration { get; }
  35. // This method gets called by the runtime. Use this method to add services to the container.
  36. public void ConfigureServices(IServiceCollection services)
  37. {
  38. // Add framework services.
  39. services.AddDbContext<ApplicationDbContext>(options =>
  40. options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  41. services.AddIdentity<ApplicationUser, IdentityRole>()
  42. .AddEntityFrameworkStores<ApplicationDbContext>()
  43. .AddDefaultTokenProviders();
  44. services.AddMvc();
  45. // Add application services.
  46. services.AddTransient<IEmailSender, AuthMessageSender>();
  47. services.AddTransient<ISmsSender, AuthMessageSender>();
  48. }
  49. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  50. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  51. {
  52. loggerFactory.AddConsole(Configuration.GetSection("Logging"));
  53. loggerFactory.AddDebug();
  54. if (env.IsDevelopment())
  55. {
  56. app.UseDeveloperExceptionPage();
  57. app.UseDatabaseErrorPage();
  58. app.UseBrowserLink();
  59. }
  60. else
  61. {
  62. app.UseExceptionHandler("/Home/Error");
  63. }
  64. app.UseStaticFiles();
  65. app.UseIdentity();
  66. // Add external authentication middleware below. To configure them please see https://go.microsoft.com/fwlink/?LinkID=532715
  67. app.UseMvc(routes =>
  68. {
  69. routes.MapRoute(
  70. name: "default",
  71. template: "{controller=Home}/{action=Index}/{id?}");
  72. });
  73. }
  74. }
  75. }