v1.1.3
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,18 +17,26 @@ namespace CC.Yi.DAL
|
||||
}
|
||||
public static DataContext GetCurrentDbContent()
|
||||
{
|
||||
//return new DataModelContainer();
|
||||
//一次请求共用一个上下文实例
|
||||
//每一次http请求都会开启一个新的线程,保证在一个线程中,DbContext是唯一的
|
||||
//CallContext:是线程内部唯一的数据槽(一块内存空间/容器),相当于一个键值对数据容器,通过key获取value了,需要引入System.Runtime.Remoting.Messaging;命名空间
|
||||
DataContext db = CallContext.GetData("DbContext") as DataContext;
|
||||
object myLock = new object();
|
||||
lock (myLock)
|
||||
{
|
||||
//return new DataModelContainer();
|
||||
//一次请求共用一个上下文实例
|
||||
//每一次http请求都会开启一个新的线程,保证在一个线程中,DbContext是唯一的
|
||||
//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是key,db是value
|
||||
}
|
||||
|
||||
|
||||
db = Webcontext;
|
||||
CallContext.SetData("DbContext", db);//放到数据槽中去,DbContext是key,db是value
|
||||
}
|
||||
|
||||
return db;
|
||||
}
|
||||
}
|
||||
|
||||
private static class CallContext
|
||||
|
||||
Reference in New Issue
Block a user