v1.1.5
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using CC.Yi.Common;
|
||||
using CC.Yi.API.Filter;
|
||||
using CC.Yi.Common;
|
||||
using CC.Yi.Common.Cache;
|
||||
using CC.Yi.IBLL;
|
||||
using CC.Yi.Model;
|
||||
@@ -15,7 +16,7 @@ namespace CC.Yi.API.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]/[action]")]
|
||||
public class StudentController : ControllerBase
|
||||
public class StudentController : Controller
|
||||
{
|
||||
private readonly ILogger<StudentController> _logger;//处理日志相关文件
|
||||
|
||||
|
||||
22
CC.Yi.API/Filter/DbContextFilter.cs
Normal file
22
CC.Yi.API/Filter/DbContextFilter.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using CC.Yi.DAL;
|
||||
using CC.Yi.Model;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CC.Yi.API.Filter
|
||||
{
|
||||
public class DbContextFilter : ActionFilterAttribute
|
||||
{
|
||||
public override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
var cache = filterContext.HttpContext.RequestServices.GetService(typeof(DataContext)) as DataContext;
|
||||
DbContentFactory.Initialize(cache);
|
||||
base.OnActionExecuting(filterContext);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
using Autofac;
|
||||
using Autofac.Extras.DynamicProxy;
|
||||
using CC.Yi.API.Filter;
|
||||
using CC.Yi.BLL;
|
||||
using CC.Yi.Common.Cache;
|
||||
using CC.Yi.Common.Castle;
|
||||
@@ -35,7 +36,7 @@ namespace CC.Yi.API
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -45,7 +46,16 @@ namespace CC.Yi.API
|
||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "CC.Yi.API", Version = "v1" });
|
||||
});
|
||||
services.AddSession();
|
||||
services.AddMvc();
|
||||
|
||||
|
||||
|
||||
//<2F><><EFBFBD>ù<EFBFBD><C3B9><EFBFBD><EFBFBD><EFBFBD>
|
||||
Action<MvcOptions> filters = new Action<MvcOptions>(r => {
|
||||
r.Filters.Add(typeof(DbContextFilter));
|
||||
});
|
||||
services.AddMvc(filters);
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>
|
||||
string connection1 = Configuration["ConnectionStringBySQL"];
|
||||
string connection2 = Configuration["ConnectionStringByMySQL"];
|
||||
string connection3 = Configuration["ConnectionStringBySQLite"];
|
||||
@@ -78,7 +88,9 @@ namespace CC.Yi.API
|
||||
// //options.User.RequireUniqueEmail = false;//ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>ظ<EFBFBD>
|
||||
// //options.User.AllowedUserNameCharacters="abcd"//<2F><><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
||||
//}).AddEntityFrameworkStores<DataContext>().AddDefaultTokenProviders();
|
||||
services.AddCors(options => options.AddPolicy("CorsPolicy",//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
services.AddCors(options => options.AddPolicy("CorsPolicy",
|
||||
builder =>
|
||||
{
|
||||
builder.AllowAnyMethod()
|
||||
@@ -88,17 +100,17 @@ namespace CC.Yi.API
|
||||
}));
|
||||
}
|
||||
|
||||
//<2F><>ʼ<EFBFBD><CABC>ʹ<EFBFBD>ú<EFBFBD><C3BA><EFBFBD>
|
||||
private void InitData(IServiceProvider serviceProvider)
|
||||
{
|
||||
var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope();
|
||||
//var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope();
|
||||
|
||||
var context = serviceScope.ServiceProvider.GetService<DataContext>();
|
||||
DbContentFactory.Initialize(context);//<2F><><EFBFBD>þ<EFBFBD>̬<EFBFBD><EFBFBD><E0B7BD>ע<EFBFBD><D7A2>
|
||||
//var context = serviceScope.ServiceProvider.GetService<DataContext>();
|
||||
//DbContentFactory.Initialize(context);//<2F><><EFBFBD>þ<EFBFBD>̬<EFBFBD><EFBFBD><E0B7BD>ע<EFBFBD><D7A2>
|
||||
}
|
||||
|
||||
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user