// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connection = Configuration.GetConnectionString("MySqlConnection"); //services.AddDbContext<CodeFrameContext>(options => options.UseMySql(connection)); //DbContext 连接池 2.0版本 services.AddDbContextPool <CodeFrameContext>(options => options.UseMySql(connection)); services.AddUnitOfWork <CodeFrameContext>();//添加UnitOfWork支持 //集中注册服务 foreach (var item in ProjectCom.GetClassName("CodeFrame.Service")) { foreach (var typeArray in item.Value) { services.AddScoped(typeArray, item.Key); } } //services.AddScoped(typeof(IUserInfoService), typeof(UserInfoService));//用ASP.NET Core自带依赖注入(DI)注入使用的类 //添加授权支持,并添加使用Cookie的方式,配置登录页面和没有权限时的跳转页面。 services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)//传入默认授权方案 .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o => { o.LoginPath = new PathString("/Account/Login"); o.AccessDeniedPath = new PathString("/Account/AccessDenied"); }); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connection = Configuration.GetConnectionString("MySqlConnection"); //services.AddDbContext<CodeFrameContext>(options => options.UseMySql(connection)); //DbContext 连接池 2.0版本 services.AddDbContextPool <CodeFrameContext>(options => options.UseMySql(connection)); services.AddUnitOfWork <CodeFrameContext>();//添加UnitOfWork支持 //集中注册服务 foreach (var item in ProjectCom.GetClassName("CodeFrame.Service")) { foreach (var typeArray in item.Value) { services.AddScoped(typeArray, item.Key); } } //services.AddScoped(typeof(IUserInfoService), typeof(UserInfoService));//用ASP.NET Core自带依赖注入(DI)注入使用的类 //添加授权支持,并添加使用Cookie的方式,配置登录页面和没有权限时的跳转页面。 services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)//传入默认授权方案 .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o => { o.LoginPath = new PathString("/Account/Login"); o.AccessDeniedPath = new PathString("/Account/AccessDenied"); }); services.AddAutoMapper(); //you can configure Json.NET to ignore cycles that it finds in the object graph services.AddMvc().AddJsonOptions( options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore ); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { ILogService <Startup> log = new LogService <Startup>(); log.Info("ConfigureServices开始"); services.AddDbContext <OrderTaskContext>(options => options.UseMySql(AppConfig.MySqlConnection)); services.AddUnitOfWork <OrderTaskContext>(); //添加UnitOfWork支持 foreach (var item in ProjectCom.GetClassName("OrderTask.Service")) //集中注入服务 { foreach (var typeArray in item.Value) { services.AddScoped(typeArray, item.Key); } } services.AddScoped(typeof(ILogService <>), typeof(LogService <>));//注入泛型loger //添加授权支持,并添加使用Cookie的方式,配置登录页面和没有权限时的跳转页面。 //https://www.cnblogs.com/seriawei/p/7452743.html services.AddAuthentication(option => { option.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; option.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme; }) //传入默认授权方案 .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o => { o.LoginPath = new PathString("/Account/Login"); o.AccessDeniedPath = new PathString("/Account/AccessDenied"); o.Events = new CookieAuthenticationEvents() { OnRedirectToLogin = (context) => context.Response.WriteAsync("<script>window.top.location.href ='/Account/Login'</script>") }; }); services.AddAutoMapper();//配置autoapper //第一个参数为配置文件路径,默认为项目目录下config.json //第二个参数为是否缓存配置文件,默认false var path = Directory.GetCurrentDirectory(); services.AddUEditorService(path + "/wwwroot/lib/UEditor/net/config.json"); services.AddMvc()//全局配置Json序列化处理 .AddJsonOptions(options => { //忽略循环引用 options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; //不使用驼峰样式的key options.SerializerSettings.ContractResolver = new DefaultContractResolver(); //设置时间格式 options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; } ); _services = services; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { ILogService <Startup> log = new LogService <Startup>(); log.Info("ConfigureServices开始"); //DbContext 连接池 2.0版本 // services.AddDbContextPool<CodeFrameContext>(options => options.UseInMemoryDatabase("mytempdb")); //内存数据库 // services.AddDbContext<CodeFrameContext>(options => options.UseInMemoryDatabase("mytempdb")); //mysql 数据库 services.AddDbContext <CodeFrameContext>(options => options.UseMySql(AppConfig.MySqlConnection)); //mssql 数据库 //services.AddDbContext<CodeFrameContext>(options => options.UseSqlServer(AppConfig.MsSqlConnection, b => b.UseRowNumberForPaging())); services.AddUnitOfWork <CodeFrameContext>(); //添加UnitOfWork支持 foreach (var item in ProjectCom.GetClassName("CodeFrame.Service")) //集中注入服务 { foreach (var typeArray in item.Value) { services.AddScoped(typeArray, item.Key); } } services.AddScoped(typeof(ILogService <>), typeof(LogService <>));//注入泛型loger //services.AddScoped(typeof(IUserInfoService), typeof(UserInfoService));//用ASP.NET Core自带依赖注入(DI)注入使用的类 //添加授权支持,并添加使用Cookie的方式,配置登录页面和没有权限时的跳转页面。 //https://www.cnblogs.com/seriawei/p/7452743.html services.AddAuthentication(option => { option.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; option.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme; }) //传入默认授权方案 .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o => { o.LoginPath = new PathString("/Account/Login"); o.AccessDeniedPath = new PathString("/Account/AccessDenied"); o.Events = new CookieAuthenticationEvents() { OnRedirectToLogin = (context) => context.Response.WriteAsync("<script>window.top.location.href ='/Account/Login'</script>") }; }); services.AddAutoMapper();//配置autoapper services.AddCors(options =>//配置跨域处理 { options.AddPolicy("any", builder => { builder.AllowAnyOrigin() //允许任何来源的主机访问 .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); //指定处理cookie }); }); services.AddMvc() //全局配置Json序列化处理 .AddJsonOptions(options => { //忽略循环引用 options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; //不使用驼峰样式的key options.SerializerSettings.ContractResolver = new DefaultContractResolver(); //设置时间格式 options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; } ); _services = services; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { ILogService <Startup> log = new LogService <Startup>(); log.Info("ConfigureServices开始"); //DbContext 连接池 2.0版本 // services.AddDbContextPool<CodeFrameContext>(options => options.UseInMemoryDatabase("mytempdb")); services.AddDbContextPool <CodeFrameContext>(options => options.UseMySql(AppConfig.MySqlConnection)); services.AddUnitOfWork <CodeFrameContext>(); //添加UnitOfWork支持 foreach (var item in ProjectCom.GetClassName("CodeFrame.Service")) //集中注入服务 { foreach (var typeArray in item.Value) { services.AddScoped(typeArray, item.Key); } } services.AddScoped(typeof(ILogService <>), typeof(LogService <>));//注入泛型loger //添加jwt授权 services.AddAuthentication(option => { option.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; option.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) //传入默认授权方案 .AddJwtBearer(o => { o.TokenValidationParameters = new TokenValidationParameters() { ValidAudience = JwtConfig.JwtConfigModel.Audience, ValidIssuer = JwtConfig.JwtConfigModel.Issuer, IssuerSigningKey = new SymmetricSecurityKey( Encoding.UTF8.GetBytes(JwtConfig.JwtConfigModel.SecretKey)) }; }); //services.AddAutoMapper();//配置autoapper services.AddCors(options =>//配置跨域处理 { options.AddPolicy("any", builder => { builder.AllowAnyOrigin() //允许任何来源的主机访问 .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); //指定处理cookie }); }); services.AddMvc()//全局配置Json序列化处理 .AddJsonOptions(options => { //忽略循环引用 options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; //不使用驼峰样式的key options.SerializerSettings.ContractResolver = new DefaultContractResolver(); //设置时间格式 options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; } ); //参考 http://www.cnblogs.com/suxinlcq/p/6757556.html services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Version = "v1", Title = "TwBusManagement接口文档", Description = "RESTful API for TwBusManagement", TermsOfService = "None", Contact = new Contact { Name = "Alvin_Su", Email = "*****@*****.**", Url = "" } }); //Set the comments path for the swagger json and ui. var basePath = PlatformServices.Default.Application.ApplicationBasePath; var xmlPath = Path.Combine(basePath, "CodeFrame.API.xml"); c.IncludeXmlComments(xmlPath); // c.OperationFilter<HttpHeaderOperation>(); // 添加httpHeader参数 }); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { ILogService <Startup> log = new LogService <Startup>(); log.Info("ConfigureServices开始"); var connection = Configuration.GetConnectionString("MySqlConnection"); //DbContext 连接池 2.0版本 services.AddDbContextPool <CodeFrameContext>(options => options.UseInMemoryDatabase("mytempdb")); // services.AddDbContextPool<CodeFrameContext>(options => options.UseMySql(connection)); services.AddUnitOfWork <CodeFrameContext>(); //添加UnitOfWork支持 foreach (var item in ProjectCom.GetClassName("CodeFrame.Service")) //集中注入服务 { foreach (var typeArray in item.Value) { services.AddScoped(typeArray, item.Key); } } services.AddScoped(typeof(ILogService <>), typeof(LogService <>));//注入泛型loger //services.AddScoped(typeof(IUserInfoService), typeof(UserInfoService));//用ASP.NET Core自带依赖注入(DI)注入使用的类 //添加授权支持,并添加使用Cookie的方式,配置登录页面和没有权限时的跳转页面。 services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)//传入默认授权方案 .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o => { o.LoginPath = new PathString("/Account/Login"); o.AccessDeniedPath = new PathString("/Account/AccessDenied"); }); services.AddAutoMapper();//配置autoapper services.AddCors(options =>//配置跨域处理 { options.AddPolicy("any", builder => { builder.AllowAnyOrigin() //允许任何来源的主机访问 .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); //指定处理cookie }); }); services.AddMvc() //全局配置Json序列化处理 .AddJsonOptions(options => { //忽略循环引用 options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; //不使用驼峰样式的key //options.SerializerSettings.ContractResolver = new DefaultContractResolver(); //设置时间格式 options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; } ); _services = services; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { ILogService <Startup> log = new LogService <Startup>(); log.Info("ConfigureServices开始"); //DbContext 连接池 2.0版本 services.AddDbContextPool <CodeFrameContext>(options => options.UseInMemoryDatabase("mytempdb")); // services.AddDbContextPool<CodeFrameContext>(options => options.UseMySql(connection)); services.AddUnitOfWork <CodeFrameContext>(); //添加UnitOfWork支持 foreach (var item in ProjectCom.GetClassName("CodeFrame.Service")) //集中注入服务 { foreach (var typeArray in item.Value) { services.AddScoped(typeArray, item.Key); } } services.AddScoped(typeof(ILogService <>), typeof(LogService <>));//注入泛型loger //services.AddScoped(typeof(IUserInfoService), typeof(UserInfoService));//用ASP.NET Core自带依赖注入(DI)注入使用的类 //添加授权支持,并添加使用Cookie的方式,配置登录页面和没有权限时的跳转页面。 //https://www.cnblogs.com/seriawei/p/7452743.html services.AddAuthentication(option => { option.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; option.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme; }) //传入默认授权方案 .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, o => { o.LoginPath = new PathString("/Account/Login"); o.AccessDeniedPath = new PathString("/Account/AccessDenied"); }); //添加jwt授权 //services.AddAuthentication(option => // { // option.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; // option.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; // }) //传入默认授权方案 // .AddJwtBearer(o => // { // o.TokenValidationParameters = new TokenValidationParameters() // { // ValidAudience = JwtConfig.JwtConfigModel.Audience, // ValidIssuer = JwtConfig.JwtConfigModel.Issuer, // IssuerSigningKey = new SymmetricSecurityKey( // Encoding.UTF8.GetBytes(JwtConfig.JwtConfigModel.SecretKey)) // }; // }); services.AddAutoMapper();//配置autoapper services.AddCors(options =>//配置跨域处理 { options.AddPolicy("any", builder => { builder.AllowAnyOrigin() //允许任何来源的主机访问 .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials(); //指定处理cookie }); }); services.AddMvc() //全局配置Json序列化处理 .AddJsonOptions(options => { //忽略循环引用 options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; //不使用驼峰样式的key //options.SerializerSettings.ContractResolver = new DefaultContractResolver(); //设置时间格式 options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; } ); _services = services; }