| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using Microsoft.AspNetCore.Authorization;
- using Api.SignToken;
- using Microsoft.IdentityModel.Tokens;
- using System.Text;
- using System.Security.Claims;
- using Microsoft.AspNetCore.Authentication.JwtBearer;
- using System.IdentityModel.Tokens.Jwt;
- using Pivotal.Discovery.Client;
- using NLog.Extensions.Logging;
- using NLog.Web;
- using Microsoft.AspNetCore.Mvc.Versioning;
- using MadRunFabric.Common.Options;
- using AutoMapper;
- using TestUserTypeApi.IRepositories;
- using TestUserTypeApi.Repositories;
- using MadRunFabric.Common;
- using MadRunFabric.Common.DbContext;
- namespace TestUserTypeApi
- {
- public class Startup
- {
- public Startup(IHostingEnvironment env)
- {
- //Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
- Configuration = new ConfigurationBuilder()
- .SetBasePath(env.ContentRootPath)
- .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
- .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
- .AddEnvironmentVariables()
- .Build();
- }
- 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)
- {
- #region Cors 配置
- ////生产环境 的cors
- //services.AddCors(options =>
- //{
- // options.AddPolicy("CorsProd",
- // builder => builder.AllowAnyOrigin()
- // //builder => builder.WithOrigins(Configuration["Cors"].Split(','))
- // .AllowAnyMethod()
- // .AllowAnyHeader()
- // .AllowCredentials().SetPreflightMaxAge(TimeSpan.FromMinutes(60)));
- //});
- ////开发环境的cors
- //services.AddCors(options =>
- //{
- // options.AddPolicy("CorsDev",
- // builder => builder.AllowAnyOrigin()
- // .AllowAnyMethod()
- // .AllowAnyHeader()
- // .AllowCredentials().SetPreflightMaxAge(TimeSpan.FromMinutes(60)));
- //});
- #endregion
- #region Cors 配置
- //生产环境 的cors
- services.AddCors(options =>
- {
- options.AddPolicy("CorsProd",
- builder => builder.AllowAnyOrigin()
- //builder => builder.WithOrigins(Configuration["Cors"].Split(','))
- .AllowAnyMethod()
- .AllowAnyHeader()
- .AllowCredentials().SetPreflightMaxAge(TimeSpan.FromMinutes(40)));
- });
- //开发环境的cors
- services.AddCors(options =>
- {
- options.AddPolicy("CorsDev",
- builder => builder.AllowAnyOrigin()
- .AllowAnyMethod()
- .AllowAnyHeader()
- .AllowCredentials().SetPreflightMaxAge(TimeSpan.FromMinutes(40)));
- });
- #endregion
- services.AddCors();
- #region 授权配置
- ////读取jwt配置文件
- //var signingKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:SecretKey"].ToString()));
- //var tokenValidationParameters = new TokenValidationParameters
- //{
- // ValidateIssuerSigningKey = true,
- // IssuerSigningKey = signingKey,
- // ValidateIssuer = true,
- // ValidIssuer = Configuration["Jwt:Issuer"].ToString(),//发行人
- // ValidateAudience = true,
- // ValidAudience = Configuration["Jwt:Audience"].ToString(),//订阅人
- // ValidateLifetime = true,
- // ClockSkew = TimeSpan.Zero,
- // RequireExpirationTime = true,
- //};
- //services.AddAuthentication(options =>
- //{
- // options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
- // options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
- //})
- //.AddJwtBearer(o =>
- //{
- // o.RequireHttpsMetadata = false;
- // o.TokenValidationParameters = tokenValidationParameters;
- // o.Events = new JwtBearerEvents
- // {
- // OnTokenValidated = context =>
- // {
- // if (context.Request.Path.Value.ToString() == "/api/logout")
- // {
- // var token = ((context as TokenValidatedContext).SecurityToken as JwtSecurityToken).RawData;
- // }
- // return Task.CompletedTask;
- // }
- // };
- //});
- #endregion
- #region configuration
- services.AddSingleton<IConfiguration>(Configuration);
- #endregion
- #region steeltoe
- services.AddDiscoveryClient(Configuration);
- #endregion
- #region redis配置
- services.AddDistributedRedisCache(options =>
- {
- options.InstanceName = Configuration["Redis:InstanceName"].ToString();
- options.Configuration = $"{Configuration["Redis:HostName"].ToString()}:{Configuration["Redis:Port"].ToString()},allowAdmin=true,password={Configuration["Redis:Password"].ToString()},defaultdatabase={Configuration["Redis:Defaultdatabase"].ToString()}";
- });
- #endregion
- services.AddSingleton<IConfiguration>(Configuration);
- //注入授权Handler
- services.AddSingleton<IAuthorizationHandler, PermissionAuthorizationHandler>();
- services.AddSingleton<IPermissionService, PermissionService>();
- services.AddSingleton<ISignTokenService, SignTokenService>();
- #region 版本控制
- services.AddApiVersioning(Options =>
- {
- Options.ReportApiVersions = true;//可选,为true API返回响应标头中支持的版本信息
- Options.ApiVersionReader = new QueryStringApiVersionReader(parameterName: "api-version");
- Options.AssumeDefaultVersionWhenUnspecified = true;
- Options.DefaultApiVersion = new Microsoft.AspNetCore.Mvc.ApiVersion(6, 0);
- });
- #endregion
- #region AutoMapper
- services.AddAutoMapper();
- #endregion
- services.AddMvc(options =>
- {
- options.Filters.Add<ActionFilter>();
- options.Filters.Add<ExceptionFilter>();
- }).AddJsonOptions(op => op.SerializerSettings.ContractResolver =
- new Newtonsoft.Json.Serialization.DefaultContractResolver());
- #region Mongodb配置
- services.Configure<MongodbOptions>(options =>
- {
- options.ConnectionString = Configuration.GetSection("MongoConnection:ConnectionString").Value;
- options.Database = Configuration.GetSection("MongoConnection:Database").Value;
- });
- BaseOracleContext.DB_ConnectionString = Configuration.GetConnectionString("OracleConnection");
- BaseOracleiihContext.DB_ConnectionString = Configuration.GetConnectionString("OracleConnectioniih");
- #endregion
- #region steeltoe
- services.AddDiscoveryClient(Configuration);
- #endregion
- #region 添加仓储访问服务
- services.AddTransient<ItestusertypeRepository, TestusertypeRepository>();
- services.AddTransient<ItesttypeRepository, TesttypeRepository>();
- services.AddTransient<IUserDoTestRepository, UserDoTestRepository>();
- services.AddTransient<IUserTestRepository, UserTestRepository>();
- services.AddTransient<IMassageInfoRepository, MassageInfoRepository>();
- services.AddTransient<ItestquestionRepository, testquestionRepository>();
- services.AddTransient<IMassageTypeRepository, MassageTypeRepository>();
- services.AddTransient<ImsgonlinemapRepository, msgonlinemapRepository>();//聊天记录是否已读关联表
- services.AddTransient<ImsgonlineRepository, msgonlineRepository>();//聊天记录表
- services.AddTransient<IdiagnosisinfoRepository, diagnosisinfoRepository>();//会诊
- services.AddTransient<IpatientRepository, patientRepository>();//患者
- services.AddTransient<IdiagnosisinbasesRepository, diagnosisinbasesRepository>();//会诊人员信息
- services.AddTransient<IequipmentmanagementsRepository, equipmentmanagementsRepository>();//设备调配设备表
- services.AddTransient<IequipmentmanagementlistRepository, equipmentmanagementlistRepository>();//设备调配记录表
- services.AddTransient<ISzzysRepository, SzzysRepository>();//上转住院
- services.AddTransient<IHzjbxxRepository, HzjbxxRepository>();//患者信息
- services.AddTransient<ISzmzsRepository, SzmzsRepository>();//上转门诊
- services.AddTransient<ISzjcsRepository, SzjcsRepository>(); //上转检查
- services.AddTransient<IXzzlsRepository, XzzlsRepository>(); //下转治疗
- services.AddTransient<IXzzysRepository, XzzysRepository>();//下转住院
- services.AddTransient<IWjzqjsRepository, WjzqjsRepository>();//急危重抢救
- services.AddTransient<IBbsqsRepository, BbsqsRepository>();//标本收取
- services.AddTransient<IHzapsRepository, HzapsRepository>();//会诊安排
- services.AddTransient<IGzlrbsRepository, GzlrbsRepository>();//工作量日报
- services.AddTransient<IYyzlsRepository, YyzlsRepository>();//预约诊疗
- services.AddTransient<IFxdjtabsRepository, FxdjtabsRepository>();//风险等级
- services.AddTransient<IFxqytabsRepository, FxqytabsRepository>();//风险区域
- services.AddTransient<IYhpctabsRepository, YhpctabsRepository>();//隐患排查
- services.AddTransient<IdxsfjlsRepository, dxsfjlsRepository>();//患者出院信息
- services.AddTransient<ISys_User_AccountRepository, Sys_User_AccountRepository>();
- services.AddTransient<ITSys_AreaRepository, TSys_AreaRepository>();//测试调用oracle
- services.AddTransient<Iv_csm_zhuyuanRepository, v_csm_zhuyuanRepository>();//出院患者信息
- services.AddTransient<IGhcodesRepository, GhcodesRepository>();//工号表
- services.AddTransient<IHzsfMassagesRepository, HzsfMassagesRepository>();//住院患者发送短信记录表
- services.AddTransient<ImzhzmassagesRepository, mzhzmassagesRepository>();//门诊患者信息表
- services.AddTransient<IyltdeptmanageRepository, yltdeptmanageRepository>();//医联体单位管理
- services.AddTransient<IMassmodellistsRepository, MassmodellistsRepository>();//在线客服消息回复模板
- services.AddTransient<IOnlineServerIfhaveRepository, OnlineServerIfhaveRepository>();//在线客服是否有新消息
- services.AddTransient<IOnlineserTypeRepository, OnlineserTypeRepository>();//客服服务类型
- services.AddTransient<ICallComeTpwodeRepository, CallComeTpwodeRepository>();//来电弹屏工单
- services.AddTransient<ICallComeDeptorPeoRepository, CallComeDeptorPeoRepository>();//科室及对应科室负责人数据维护
- services.AddTransient<Iyjpt_jcxxRepository, yjpt_jcxxRepository>();//检查信息iih数据
- services.AddTransient<IyyjlinfolistRepository, yyjlinfolistRepository>();//预约记录信息表
- services.AddTransient<IFpzxinfosRepository, FpzxinfosRepository>();//分配在线客服表
- services.AddTransient<IimportmassageRepository, importmassageRepository>();//通知公告信息表管理
- services.AddTransient<IYytxluinfoRepository, YytxluinfoRepository>();//第三方通话通讯录
- #endregion
- //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
- }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
- {
- if (env.IsProduction())
- {
- app.UseCors("CorsProd");
- }
- else
- {
- app.UseCors("CorsDev");
- app.UseDeveloperExceptionPage();
- app.UseDatabaseErrorPage();
- app.UseBrowserLink();
- }
- app.UseCors(builder => builder
- .AllowAnyOrigin()
- .AllowAnyMethod()
- .AllowAnyHeader()
- .AllowCredentials());
- app.UseAuthentication();
- app.UseMvc();
- #region steeltoe
- app.UseDiscoveryClient();
- #endregion
- #region Nlog 引入
- loggerFactory.AddNLog();//添加NLog
- env.ConfigureNLog("nlog.config");//读取Nlog配置文件
- app.AddNLogWeb();
- #endregion
- }
- }
- }
|