using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; using Quartz; using Quartz.Impl; using Swashbuckle.AspNetCore.Filters; using System; using System.IO; using System.Text; using Microsoft.EntityFrameworkCore; using IMCS.CCS.Repository; using IMCS.CCS.Service; using IMCS.CCS.Service.Impl; using IMCS.CCS.Services; using IMCS.CCS.Filter; using IMCS.CCS.Config; using IMCS.CCS.Service.Jobs; using IMCS.CCS.Common.Redis; namespace IMCS.CCS { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(options => { options.Filters.Add(); }) ; services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "IMCS.CCS", Version = "v1" }); //为 Swagger JSON and UI设置xml文档注释路径 var xmlPath = Path.Combine(AppContext.BaseDirectory, "IMCS.CCS.xml"); c.IncludeXmlComments(xmlPath, true); }); //使用mysql services.AddDbContext(options => options.UseMySQL(Configuration.GetConnectionString("mysqlContext")) .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)); services.AddCors(options => { options.AddPolicy("HZYCors", builder => { builder.WithOrigins("*") .AllowAnyMethod() .AllowAnyHeader(); //.AllowAnyOrigin() //.AllowCredentials(); //6877 }); }); #region 实例注册 //AutoMapper 配置 services.AddAutoMapper(typeof(AutoMapperConfig)); //文件数据服务 services.AddTransient(); //项目服务 services.AddTransient(); //任务服务 services.AddTransient(); //定时任务 服务 services.AddTransient(); //注册ISchedulerFactory的实例。 services.AddTransient(); //web api 请求服务 services.AddTransient(); //Job 实例化工厂 services.AddSingleton(); //Reultful 风格 api 请求 任务 services.AddTransient(); //任务日志 services.AddSingleton(); //项目配置信息 services.AddSingleton(); //redis 注册 RepositoryRedisModule.RegisterRedisRepository(services, Configuration["RedisConnectionString"]); //services.AddScoped(); services.AddTransient(); services.AddTransient(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); #endregion } // 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(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "IMCS.CCS v1")); } app.UseCors("HZYCors"); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); //app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } } }