using System; using System.IO; using System.Text.Encodings.Web; using System.Text.Unicode; using Falcon.Extend; using FAuth.DataBase; using FAuth.Extensions.Decryptor; using FAuth.Models; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Redis; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.OpenApi.Models; namespace FAuth { /// /// 应用设置 /// public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } /// /// 注册到服务容器 /// /// 服务容器 public void ConfigureServices(IServiceCollection services) { //注册Json序列化 services.AddMsJsonProvider(); //注册数据库 services.AddDbContext(option => { option.UseSqlServer(Configuration.GetConnectionString("FAuthDb")); }); //注册Redis var rop = this.Configuration.GetSection("Redis").Get(); services.AddRedis(rop); //注册MVC services.AddControllersWithViews() .AddJsonOptions(option => { option.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All); option.JsonSerializerOptions.PropertyNamingPolicy = null; }); //注册Swagger services.AddSwaggerGen(c => { c.SwaggerDoc("V1",new OpenApiInfo { Title = "接口文档", Version = "1.0", Description = "api", Contact = new OpenApiContact { Name = "Falcon", Url = new Uri("http://39.105.71.191/Falcon/FAuth"), }, }); var xmlPath = Path.Combine(AppContext.BaseDirectory,typeof(Program).Assembly.GetName().Name + ".xml"); c.IncludeXmlComments(xmlPath,true); c.AddXmlEnumEnable(xmlPath); }); //注册用户票据生成器 services.AddAESCrypto(); var UTDO = Configuration.GetSection("UserTicketDecryptorOption"); services.AddUserTicketDryptor(UTDO); //注册api错误处理器 services.AddScoped(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app,IWebHostEnvironment env) { if(env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/V1/swagger.json","接口文档"); c.RoutePrefix = ""; }); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); } } }