This commit is contained in:
454313500@qq.com
2021-04-13 12:42:37 +08:00
parent 8673e8fd85
commit d9e826af68
3 changed files with 31 additions and 23 deletions

View File

@@ -1,6 +1,6 @@
using CC.Yi.IBLL; using CC.Yi.Common;
using CC.Yi.IBLL;
using CC.Yi.Model; using CC.Yi.Model;
using Common;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;

View File

@@ -3,37 +3,37 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Web; using System.Web;
namespace Common namespace CC.Yi.Common
{ {
/// <summary> /// <summary>
/// 结果数据 /// 结果数据
/// </summary> /// </summary>
public class Result public class Result
{ {
public bool Status { get; set; } public bool status { get; set; }
public int Code { get; set; } public int code { get; set; }
public string Msg { get; set; } public string msg { get; set; }
public object Data { get; set; } public object data { get; set; }
public static Result Instance(bool status, string msg) public static Result Instance(bool status, string msg)
{ {
return new Result() { Status = status,Code=500, Msg = msg }; return new Result() { status = status, code = 500, msg = msg };
} }
public static Result Error(string msg) public static Result Error(string msg = "fail")
{ {
return new Result() { Status = false, Code = 500, Msg = msg }; return new Result() { status = false, code = 500, msg = msg };
} }
public static Result Success(string msg= "succeed") public static Result Success(string msg = "succeed")
{ {
return new Result() { Status = true, Code = 200, Msg = msg }; return new Result() { status = true, code = 200, msg = msg };
} }
public Result SetData(object obj) public Result SetData(object obj)
{ {
this.Data = obj; this.data = obj;
return this; return this;
} }
public Result SetCode(int Code) public Result SetCode(int Code)
{ {
this.Code = Code; this.code = Code;
return this; return this;
} }
} }

View File

@@ -16,6 +16,9 @@ namespace CC.Yi.DAL
Webcontext = webContext; Webcontext = webContext;
} }
public static DataContext GetCurrentDbContent() public static DataContext GetCurrentDbContent()
{
object myLock = new object();
lock (myLock)
{ {
//return new DataModelContainer(); //return new DataModelContainer();
//一次请求共用一个上下文实例 //一次请求共用一个上下文实例
@@ -23,13 +26,18 @@ namespace CC.Yi.DAL
//CallContext是线程内部唯一的数据槽一块内存空间/容器),相当于一个键值对数据容器通过key获取value了,需要引入System.Runtime.Remoting.Messaging;命名空间 //CallContext是线程内部唯一的数据槽一块内存空间/容器),相当于一个键值对数据容器通过key获取value了,需要引入System.Runtime.Remoting.Messaging;命名空间
DataContext db = CallContext.GetData("DbContext") as DataContext; DataContext db = CallContext.GetData("DbContext") as DataContext;
//从 CallContext 中检索具有指定key“DbContext”的对象并强转为DbContext //从 CallContext 中检索具有指定key“DbContext”的对象并强转为DbContext
if (db == null)//线程在数据槽里面没有此上下文 if (db == null)//线程在数据槽里面没有此上下文
{ {
db = Webcontext; db = Webcontext;
CallContext.SetData("DbContext", db);//放到数据槽中去,DbContext是keydb是value CallContext.SetData("DbContext", db);//放到数据槽中去,DbContext是keydb是value
} }
return db; return db;
} }
}
private static class CallContext private static class CallContext
{ {