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 Common;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

View File

@@ -3,37 +3,37 @@ using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Common
namespace CC.Yi.Common
{
/// <summary>
/// 结果数据
/// </summary>
public class Result
{
public bool Status { get; set; }
public int Code { get; set; }
public string Msg { get; set; }
public object Data { get; set; }
public bool status { get; set; }
public int code { get; set; }
public string msg { get; set; }
public object data { get; set; }
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)
{
this.Data = obj;
this.data = obj;
return this;
}
public Result SetCode(int Code)
{
this.Code = Code;
this.code = Code;
return this;
}
}

View File

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