Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Startup.cs 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using Microsoft.AspNetCore.Builder;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.AspNetCore.HttpsPolicy;
  4. using Microsoft.AspNetCore.Identity;
  5. using Microsoft.Extensions.Configuration;
  6. using Microsoft.Extensions.DependencyInjection;
  7. using Microsoft.Extensions.Hosting;
  8. using MVCTemplate.Business.Infrastructure;
  9. using MVCTemplate.Business.Infrastructure.Extensions;
  10. using MVCTemplate.Business.Infrastructure.Settings;
  11. using MVCTemplate.Business.Interfaces;
  12. using MVCTemplate.Business.Services;
  13. using MVCTemplate.Data.DbContexts;
  14. using MVCTemplate.Infrastructure;
  15. using MVCTemplate.Infrastructure.Middleware;
  16. using MVCTemplate.Quartz;
  17. using Quartz;
  18. using Quartz.Impl;
  19. using Quartz.Spi;
  20. using System;
  21. using System.Collections.Generic;
  22. using System.Linq;
  23. using System.Threading.Tasks;
  24. namespace MVCTemplate
  25. {
  26. public class Startup
  27. {
  28. public Startup(IConfiguration configuration)
  29. {
  30. Configuration = configuration;
  31. }
  32. public IConfiguration Configuration { get; }
  33. // This method gets called by the runtime. Use this method to add services to the container.
  34. public void ConfigureServices(IServiceCollection services)
  35. {
  36. StartupConfiguration.ConfigureStartupConfig<EmailSettings>(services, Configuration);
  37. services.AddControllersWithViews();
  38. services.AddRazorPages();
  39. StartupExtensions.ConfigureServices(services);
  40. services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = false)
  41. .AddDefaultUI()
  42. .AddRoles<IdentityRole>()
  43. .AddEntityFrameworkStores<AppDbContext>();
  44. services.AddScoped<IMessageService, MessageService>();
  45. services.AddScoped<IModelFactory, ModelFactory>();
  46. services.AddAuthentication()
  47. .AddGoogle(options =>
  48. {
  49. options.ClientId = Configuration.GetSection("EmailSettings").GetSection("ClientId").Value;
  50. options.ClientSecret = Configuration.GetSection("EmailSettings").GetSection("ClientSecret").Value;
  51. });
  52. // Add Quartz services
  53. services.AddSingleton<IJobFactory, JobFactory>();
  54. services.AddSingleton<ISchedulerFactory, StdSchedulerFactory>();
  55. // Add our jobs
  56. services.AddScoped<MessageDeletionJob>();
  57. services.AddSingleton(new JobMetadata(
  58. jobType: typeof(MessageDeletionJob),
  59. cronExpression: "0 0 12 * * ?"));
  60. services.AddHostedService<JobsService>();
  61. }
  62. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  63. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  64. {
  65. if (env.IsDevelopment())
  66. {
  67. app.UseDeveloperExceptionPage();
  68. }
  69. else
  70. {
  71. app.UseExceptionHandler("/Home/Error");
  72. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  73. app.UseHsts();
  74. }
  75. app.UseHttpsRedirection();
  76. app.UseStaticFiles();
  77. app.UseRouting();
  78. app.UseAuthentication();
  79. app.UseAuthorization();
  80. app.UseMiddleware(typeof(ExceptionHandlingMiddleware));
  81. app.UseEndpoints(endpoints =>
  82. {
  83. endpoints.MapControllerRoute(
  84. name: "default",
  85. pattern: "{controller=Home}/{action=Index}/{id?}");
  86. endpoints.MapRazorPages();
  87. });
  88. }
  89. }
  90. }