Startup.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. using CZFW.Core;
  7. using CZFW.Framework;
  8. using CZFW.Framework.Logic;
  9. using CZFW.Framework.Model;
  10. using CZFW.Logger;
  11. using CZKJ.GBRS2.Web.AppCode;
  12. using log4net;
  13. using log4net.Config;
  14. using log4net.Repository;
  15. using Microsoft.AspNetCore.Builder;
  16. using Microsoft.AspNetCore.Hosting;
  17. using Microsoft.EntityFrameworkCore;
  18. using Microsoft.Extensions.Configuration;
  19. using Microsoft.Extensions.DependencyInjection;
  20. using Microsoft.Extensions.Logging;
  21. namespace CZKJ.GBRS2.Web
  22. {
  23. public class Startup
  24. {
  25. public static ILoggerRepository repository { get; set; }
  26. public Startup(IConfiguration configuration)
  27. {
  28. Configuration = configuration;
  29. ConfigHelper.Configs = Configuration;
  30. repository = LogManager.CreateRepository("NetCoreRepository");
  31. XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
  32. InitRepository.loggerRepository = repository;
  33. }
  34. public IConfiguration 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. services.AddDbContext<CZDbContext>();
  39. services.AddMvc(o => o.Filters.Add(typeof(GlobalExceptions)));
  40. services.AddSession();
  41. services.ConfigServies();
  42. services.AddLogging();
  43. services.AddMemoryCache();
  44. services.AddLogging();
  45. services.ConfigureFrameworkServices();
  46. CZHttpContext.ServiceProvider = services.BuildServiceProvider();
  47. }
  48. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  49. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger)
  50. {
  51. if (env.IsDevelopment())
  52. {
  53. app.UseBrowserLink();
  54. app.UseDeveloperExceptionPage();
  55. }
  56. else
  57. {
  58. app.UseExceptionHandler("/Home/Error");
  59. }
  60. app.UseSession();
  61. app.UseStaticFiles();
  62. app.UseMvc(routes =>
  63. {
  64. routes.MapRoute(
  65. name: "araas",
  66. template: "{area=exists}/{controller=Home}/{action=Index}/{id?}"
  67. );
  68. routes.MapRoute(
  69. name: "default",
  70. template: "{controller=Home}/{action=Index}/{id?}");
  71. });
  72. }
  73. }
  74. }