Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwplvx
Aurora
提交
6ab69f5b
Aurora
项目概览
lwplvx
/
Aurora
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Aurora
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6ab69f5b
编写于
5月 27, 2021
作者:
lwplvx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename files
上级
db7aa644
变更
22
隐藏空白更改
内联
并排
Showing
22 changed file
with
146 addition
and
67 deletion
+146
-67
Aurora.Common/CommonExtensions.cs
Aurora.Common/CommonExtensions.cs
+33
-0
Aurora.Common/CurrentProvider.cs
Aurora.Common/CurrentProvider.cs
+1
-1
Aurora.Common/Tenant/CurrentTenantProvider.cs
Aurora.Common/Tenant/CurrentTenantProvider.cs
+13
-16
Aurora.Common/Tenant/TenantContext.cs
Aurora.Common/Tenant/TenantContext.cs
+1
-1
Aurora.Common/User/UserContext.cs
Aurora.Common/User/UserContext.cs
+1
-1
Aurora.Common/User/UserContextProvider.cs
Aurora.Common/User/UserContextProvider.cs
+14
-14
Aurora.Common/User/UsersCache.cs
Aurora.Common/User/UsersCache.cs
+9
-0
Aurora.Infrastructure/Response/ResponseModel.cs
Aurora.Infrastructure/Response/ResponseModel.cs
+2
-2
Aurora.Infrastructure/Tenant/ITenantContext.cs
Aurora.Infrastructure/Tenant/ITenantContext.cs
+1
-1
Aurora.Infrastructure/Tenant/ITenantContextProvider.cs
Aurora.Infrastructure/Tenant/ITenantContextProvider.cs
+10
-0
Aurora.Infrastructure/User/IUserContext.cs
Aurora.Infrastructure/User/IUserContext.cs
+1
-1
Aurora.Infrastructure/User/IUserContextProvider.cs
Aurora.Infrastructure/User/IUserContextProvider.cs
+9
-0
Aurora.Infrastructure/User/IUsersCache.cs
Aurora.Infrastructure/User/IUsersCache.cs
+7
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.Api/ModuleCoreApi.cs
...icorservices/Aurora.Core/Aurora.Core.Api/ModuleCoreApi.cs
+0
-5
Aurora.Micorservices/Aurora.Core/Aurora.Core.Api/Startup.cs
Aurora.Micorservices/Aurora.Core/Aurora.Core.Api/Startup.cs
+4
-2
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/Entities/Category.cs
...vices/Aurora.Core/Aurora.Core.Domain/Entities/Category.cs
+1
-0
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/Entities/EntityBase.cs
...ces/Aurora.Core/Aurora.Core.Domain/Entities/EntityBase.cs
+2
-1
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/Entities/TenantEntityBase.cs
...rora.Core/Aurora.Core.Domain/Entities/TenantEntityBase.cs
+2
-1
Aurora.Micorservices/Aurora.Core/Aurora.Core.EntityFramework/ApplicationDbContext.cs
....Core/Aurora.Core.EntityFramework/ApplicationDbContext.cs
+13
-11
Aurora.Micorservices/Aurora.Core/Aurora.Core.EntityFramework/ApplicationReadonlyDbContext.cs
...rora.Core.EntityFramework/ApplicationReadonlyDbContext.cs
+9
-10
Thinking.md
Thinking.md
+11
-0
scripts/category.sql
scripts/category.sql
+2
-0
未找到文件。
Aurora.Common/CommonExtensions.cs
0 → 100644
浏览文件 @
6ab69f5b
using
System
;
using
System.Reflection
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.AspNetCore.Http
;
using
Aurora.Infrastructure.User
;
using
Aurora.Infrastructure.Tenant
;
using
Aurora.Common.User
;
using
Aurora.Common.Tenant
;
namespace
Aurora.Common
{
public
static
class
CommonExtensions
{
public
static
IServiceCollection
AddCommonService
(
this
IServiceCollection
services
)
{
if
(
services
==
null
)
{
throw
new
ArgumentNullException
(
"services"
);
}
//注入请求上下文
services
.
AddSingleton
<
IHttpContextAccessor
,
HttpContextAccessor
>();
services
.
AddSingleton
<
IUsersCache
,
UsersCache
>();
services
.
AddScoped
<
IUserContextProvider
,
UserContextProvider
>();
services
.
AddScoped
<
ITenantContextProvider
,
TenantContextProvider
>();
return
services
;
}
}
}
Aurora.Common/CurrentProvider.cs
浏览文件 @
6ab69f5b
...
@@ -18,7 +18,7 @@ namespace Aurora.Common
...
@@ -18,7 +18,7 @@ namespace Aurora.Common
/// </summary>
/// </summary>
public
string
TenantCode
{
get
;
set
;
}
public
string
TenantCode
{
get
;
set
;
}
public
I
CurrentUser
CurrentUser
{
get
;
set
;
}
public
I
UserContext
CurrentUser
{
get
;
set
;
}
public
T
RequestEntity
{
get
;
set
;
}
public
T
RequestEntity
{
get
;
set
;
}
}
}
...
...
Aurora.Common/Tenant/CurrentTenantProvider.cs
浏览文件 @
6ab69f5b
...
@@ -7,36 +7,33 @@ using Aurora.Infrastructure.Tenant;
...
@@ -7,36 +7,33 @@ using Aurora.Infrastructure.Tenant;
namespace
Aurora.Common.Tenant
namespace
Aurora.Common.Tenant
{
{
public
class
CurrentTenantProvider
:
ICurrentTenan
tProvider
public
class
TenantContextProvider
:
ITenantContex
tProvider
{
{
private
CurrentTenant
currentTenant
{
get
;
set
;
}
readonly
IHttpContextAccessor
_httpContextAccessor
;
public
TenantContextProvider
(
IHttpContextAccessor
httpContextAccessor
)
IHttpContextAccessor
httpContextAccessor
;
public
CurrentTenantProvider
(
IHttpContextAccessor
_httpContextAccessor
)
{
{
httpContextAccessor
=
_
httpContextAccessor
;
_httpContextAccessor
=
httpContextAccessor
;
}
}
public
I
CurrentTenant
GetCurrentTenan
t
()
public
I
TenantContext
GetTenantContex
t
()
{
{
CurrentTenant
_currentTenant
=
new
CurrentTenant
();
TenantContext
tenantContext
=
new
();
if
(
httpContextAccessor
.
HttpContext
==
null
)
//cap
if
(
_
httpContextAccessor
.
HttpContext
==
null
)
//cap
{
{
//todo
//todo
_currentTenant
=
currentTenant
;
}
}
else
if
(
httpContextAccessor
.
HttpContext
.
User
!=
null
&&
else
if
(
_
httpContextAccessor
.
HttpContext
.
User
!=
null
&&
httpContextAccessor
.
HttpContext
.
User
.
Identity
.
IsAuthenticated
)
//external
_
httpContextAccessor
.
HttpContext
.
User
.
Identity
.
IsAuthenticated
)
//external
{
{
ClaimsPrincipal
claimsPrincipal
=
httpContextAccessor
.
HttpContext
.
User
;
ClaimsPrincipal
claimsPrincipal
=
_
httpContextAccessor
.
HttpContext
.
User
;
var
subject
=
claimsPrincipal
.
Claims
.
FirstOrDefault
(
w
=>
w
.
Type
==
JwtClaimTypes
.
Role
);
var
subject
=
claimsPrincipal
.
Claims
.
FirstOrDefault
(
w
=>
w
.
Type
==
JwtClaimTypes
.
Role
);
_currentTenan
t
.
TenantCode
=
subject
.
Value
;
tenantContex
t
.
TenantCode
=
subject
.
Value
;
}
}
else
//internal
else
//internal
{
{
_currentTenant
.
TenantCode
=
httpContextAccessor
.
HttpContext
.
Request
.
Headers
[
ConstString
.
CurrentTenantCode
].
FirstOrDefault
();
tenantContext
.
TenantCode
=
_
httpContextAccessor
.
HttpContext
.
Request
.
Headers
[
ConstString
.
CurrentTenantCode
].
FirstOrDefault
();
}
}
return
_currentTenan
t
;
return
tenantContex
t
;
}
}
}
}
...
...
Aurora.Common/Tenant/
CurrentTenan
t.cs
→
Aurora.Common/Tenant/
TenantContex
t.cs
浏览文件 @
6ab69f5b
...
@@ -6,7 +6,7 @@ using Aurora.Infrastructure.Tenant;
...
@@ -6,7 +6,7 @@ using Aurora.Infrastructure.Tenant;
namespace
Aurora.Common.Tenant
namespace
Aurora.Common.Tenant
{
{
public
class
CurrentTenant
:
ICurrentTenan
t
public
class
TenantContext
:
ITenantContex
t
{
{
public
string
TenantCode
{
get
;
set
;
}
public
string
TenantCode
{
get
;
set
;
}
}
}
...
...
Aurora.Common/User/
CurrentUser
.cs
→
Aurora.Common/User/
UserContext
.cs
浏览文件 @
6ab69f5b
...
@@ -13,7 +13,7 @@ using Aurora.Common.Permission;
...
@@ -13,7 +13,7 @@ using Aurora.Common.Permission;
namespace
Aurora.Common.User
namespace
Aurora.Common.User
{
{
public
class
CurrentUser
:
ICurrentUser
public
class
UserContext
:
IUserContext
{
{
/// <summary>
/// <summary>
/// 用户登录用户Code
/// 用户登录用户Code
...
...
Aurora.Common/User/
CurrentUser
Provider.cs
→
Aurora.Common/User/
UserContext
Provider.cs
浏览文件 @
6ab69f5b
...
@@ -11,28 +11,28 @@ using Aurora.Infrastructure.User;
...
@@ -11,28 +11,28 @@ using Aurora.Infrastructure.User;
namespace
Aurora.Common.User
namespace
Aurora.Common.User
{
{
public
class
CurrentUserProvider
:
ICurrentUser
Provider
public
class
UserContextProvider
:
IUserContext
Provider
{
{
IHttpContextAccessor
httpContextAccessor
;
readonly
IHttpContextAccessor
_
httpContextAccessor
;
IConfiguration
_configuration
;
readonly
IUsersCache
_usersCache
;
public
CurrentUserProvider
(
IHttpContextAccessor
_httpContextAccessor
,
IConfiguration
configuration
)
public
UserContextProvider
(
IHttpContextAccessor
httpContextAccessor
,
IUsersCache
usersCache
)
{
{
httpContextAccessor
=
_
httpContextAccessor
;
_httpContextAccessor
=
httpContextAccessor
;
_
configuration
=
configuration
;
_
usersCache
=
usersCache
;
}
}
public
I
CurrentUser
GetCurrentUser
()
public
I
UserContext
GetUserContext
()
{
{
I
CurrentUser
currentUser
=
new
CurrentUser
();
I
UserContext
currentUser
=
new
UserContext
();
if
(
httpContextAccessor
.
HttpContext
==
null
)
//cap
if
(
_
httpContextAccessor
.
HttpContext
==
null
)
//cap
{
{
currentUser
.
UserCode
=
"cap"
;
currentUser
.
UserCode
=
"cap"
;
currentUser
.
UserName
=
"cap"
;
currentUser
.
UserName
=
"cap"
;
}
}
else
if
(
httpContextAccessor
.
HttpContext
.
User
!=
null
&&
else
if
(
_
httpContextAccessor
.
HttpContext
.
User
!=
null
&&
httpContextAccessor
.
HttpContext
.
User
.
Identity
.
IsAuthenticated
)
//external
_
httpContextAccessor
.
HttpContext
.
User
.
Identity
.
IsAuthenticated
)
//external
{
{
ClaimsPrincipal
claimsPrincipal
=
httpContextAccessor
.
HttpContext
.
User
;
ClaimsPrincipal
claimsPrincipal
=
_
httpContextAccessor
.
HttpContext
.
User
;
var
subject
=
claimsPrincipal
.
Claims
.
FirstOrDefault
(
w
=>
w
.
Type
==
JwtClaimTypes
.
Subject
);
var
subject
=
claimsPrincipal
.
Claims
.
FirstOrDefault
(
w
=>
w
.
Type
==
JwtClaimTypes
.
Subject
);
var
subjectRole
=
claimsPrincipal
.
Claims
.
FirstOrDefault
(
w
=>
w
.
Type
==
JwtClaimTypes
.
Role
);
var
subjectRole
=
claimsPrincipal
.
Claims
.
FirstOrDefault
(
w
=>
w
.
Type
==
JwtClaimTypes
.
Role
);
...
@@ -46,10 +46,10 @@ namespace Aurora.Common.User
...
@@ -46,10 +46,10 @@ namespace Aurora.Common.User
return
currentUser
;
return
currentUser
;
}
}
private
I
CurrentUser
GetCurrentUserFromRedis
(
string
usercode
,
string
tenantCode
)
private
I
UserContext
GetCurrentUserFromRedis
(
string
usercode
,
string
tenantCode
)
{
{
// var redisUserInfo = new CacheRedis(RedisDBType.User, _configuration).GetJSON<CurrentUserInfo>($"{tenantCode}:{usercode}");
// var redisUserInfo = new CacheRedis(RedisDBType.User, _configuration).GetJSON<CurrentUserInfo>($"{tenantCode}:{usercode}");
return
new
CurrentUser
();
return
new
UserContext
();
// return redisUserInfo;
// return redisUserInfo;
}
}
}
}
...
...
Aurora.Common/User/UsersCache.cs
0 → 100644
浏览文件 @
6ab69f5b
using
Aurora.Infrastructure.User
;
namespace
Aurora.Common.User
{
public
class
UsersCache
:
IUsersCache
{
}
}
\ No newline at end of file
Aurora.Infrastructure/Response/ResponseModel.cs
浏览文件 @
6ab69f5b
...
@@ -7,9 +7,9 @@ namespace Aurora.Infrastructure.Response
...
@@ -7,9 +7,9 @@ namespace Aurora.Infrastructure.Response
{
{
public
class
ResponseModel
<
T
>
public
class
ResponseModel
<
T
>
{
{
ErrorCodes
ErrorCode
{
get
;
set
;
}
public
ErrorCodes
ErrorCode
{
get
;
set
;
}
T
Data
{
get
;
set
;
}
public
T
Data
{
get
;
set
;
}
public
ResponseModel
(
T
data
)
public
ResponseModel
(
T
data
)
{
{
...
...
Aurora.Infrastructure/Tenant/I
CurrentTenan
t.cs
→
Aurora.Infrastructure/Tenant/I
TenantContex
t.cs
浏览文件 @
6ab69f5b
...
@@ -2,7 +2,7 @@ using System;
...
@@ -2,7 +2,7 @@ using System;
namespace
Aurora.Infrastructure.Tenant
namespace
Aurora.Infrastructure.Tenant
{
{
public
interface
I
CurrentTenan
t
public
interface
I
TenantContex
t
{
{
string
TenantCode
{
get
;
set
;
}
string
TenantCode
{
get
;
set
;
}
...
...
Aurora.Infrastructure/Tenant/I
CurrentTenan
tProvider.cs
→
Aurora.Infrastructure/Tenant/I
TenantContex
tProvider.cs
浏览文件 @
6ab69f5b
...
@@ -2,9 +2,9 @@ using System;
...
@@ -2,9 +2,9 @@ using System;
namespace
Aurora.Infrastructure.Tenant
namespace
Aurora.Infrastructure.Tenant
{
{
public
interface
I
CurrentTenan
tProvider
public
interface
I
TenantContex
tProvider
{
{
I
CurrentTenant
GetCurrentTenan
t
();
I
TenantContext
GetTenantContex
t
();
}
}
}
}
Aurora.Infrastructure/User/I
CurrentUser
.cs
→
Aurora.Infrastructure/User/I
UserContext
.cs
浏览文件 @
6ab69f5b
...
@@ -5,7 +5,7 @@ using System.Collections.Generic;
...
@@ -5,7 +5,7 @@ using System.Collections.Generic;
namespace
Aurora.Infrastructure.User
namespace
Aurora.Infrastructure.User
{
{
public
interface
I
CurrentUser
public
interface
I
UserContext
{
{
/// <summary>
/// <summary>
/// 用户登录用户Code
/// 用户登录用户Code
...
...
Aurora.Infrastructure/User/I
CurrentUser
Provider.cs
→
Aurora.Infrastructure/User/I
UserContext
Provider.cs
浏览文件 @
6ab69f5b
...
@@ -2,8 +2,8 @@ using System;
...
@@ -2,8 +2,8 @@ using System;
namespace
Aurora.Infrastructure.User
namespace
Aurora.Infrastructure.User
{
{
public
interface
I
CurrentUser
Provider
public
interface
I
UserContext
Provider
{
{
I
CurrentUser
GetCurrentUser
();
I
UserContext
GetUserContext
();
}
}
}
}
Aurora.Infrastructure/User/IUsersCache.cs
0 → 100644
浏览文件 @
6ab69f5b
namespace
Aurora.Infrastructure.User
{
public
interface
IUsersCache
{
}
}
\ No newline at end of file
Aurora.Micorservices/Aurora.Core/Aurora.Core.Api/ModuleCoreApi.cs
浏览文件 @
6ab69f5b
...
@@ -25,11 +25,6 @@ namespace Aurora.Core.Api
...
@@ -25,11 +25,6 @@ namespace Aurora.Core.Api
services
.
AddAutoMapper
(
Assembly
.
Load
(
"Aurora.Core.Service"
));
services
.
AddAutoMapper
(
Assembly
.
Load
(
"Aurora.Core.Service"
));
//注入请求上下文
services
.
AddSingleton
<
IHttpContextAccessor
,
HttpContextAccessor
>();
services
.
AddScoped
<
ICurrentUserProvider
,
CurrentUserProvider
>();
services
.
AddScoped
<
ICurrentTenantProvider
,
CurrentTenantProvider
>();
services
.
AddDbContext
<
ApplicationDbContext
>(
option
=>
services
.
AddDbContext
<
ApplicationDbContext
>(
option
=>
option
.
UseMySQL
(
configuration
[
"ConnectionStrings:MySql"
]));
option
.
UseMySQL
(
configuration
[
"ConnectionStrings:MySql"
]));
services
.
AddDbContext
<
ApplicationReadonlyDbContext
>(
option
=>
services
.
AddDbContext
<
ApplicationReadonlyDbContext
>(
option
=>
...
...
Aurora.Micorservices/Aurora.Core/Aurora.Core.Api/Startup.cs
浏览文件 @
6ab69f5b
...
@@ -15,6 +15,7 @@ using Microsoft.OpenApi.Models;
...
@@ -15,6 +15,7 @@ using Microsoft.OpenApi.Models;
using
System.IO
;
using
System.IO
;
using
Aurora.Core.EntityFramework
;
using
Aurora.Core.EntityFramework
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore
;
using
Aurora.Common
;
namespace
Aurora.Core.Api
namespace
Aurora.Core.Api
{
{
...
@@ -36,9 +37,10 @@ namespace Aurora.Core.Api
...
@@ -36,9 +37,10 @@ namespace Aurora.Core.Api
{
{
c
.
SwaggerDoc
(
"v1"
,
new
OpenApiInfo
{
Title
=
"Aurora.Core.Api"
,
Version
=
"v1"
});
c
.
SwaggerDoc
(
"v1"
,
new
OpenApiInfo
{
Title
=
"Aurora.Core.Api"
,
Version
=
"v1"
});
});
});
services
.
AddModuleCoreApi
(
Configuration
);
services
.
AddCommonService
();
services
.
AddModuleCoreApi
(
Configuration
);
}
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
...
...
Aurora.Micorservices/Aurora.Core/Aurora.Core.Domain/Entities/Category.cs
浏览文件 @
6ab69f5b
...
@@ -5,6 +5,7 @@ namespace Aurora.Core.Domain.Entities
...
@@ -5,6 +5,7 @@ namespace Aurora.Core.Domain.Entities
{
{
public
class
Category
:
TenantEntityBase
public
class
Category
:
TenantEntityBase
{
{
public
int
ParentId
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
string
Remark
{
get
;
set
;
}
public
string
Remark
{
get
;
set
;
}
}
}
...
...
Aurora.
Commo
n/Entities/EntityBase.cs
→
Aurora.
Micorservices/Aurora.Core/Aurora.Core.Domai
n/Entities/EntityBase.cs
浏览文件 @
6ab69f5b
using
System
;
using
System
;
using
Aurora.Common.Entities
;
namespace
Aurora.
Commo
n.Entities
namespace
Aurora.
Domai
n.Entities
{
{
public
class
EntityBase
:
IEntity
public
class
EntityBase
:
IEntity
{
{
...
...
Aurora.
Commo
n/Entities/TenantEntityBase.cs
→
Aurora.
Micorservices/Aurora.Core/Aurora.Core.Domai
n/Entities/TenantEntityBase.cs
浏览文件 @
6ab69f5b
using
System
;
using
System
;
using
Aurora.Common.Entities
;
namespace
Aurora.
Commo
n.Entities
namespace
Aurora.
Domai
n.Entities
{
{
public
class
TenantEntityBase
:
EntityBase
,
ITenantEntity
public
class
TenantEntityBase
:
EntityBase
,
ITenantEntity
{
{
...
...
Aurora.Micorservices/Aurora.Core/Aurora.Core.EntityFramework/ApplicationDbContext.cs
浏览文件 @
6ab69f5b
...
@@ -10,6 +10,7 @@ using System.Threading;
...
@@ -10,6 +10,7 @@ using System.Threading;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Aurora.Common.Entities
;
using
Aurora.Common.Entities
;
using
Aurora.Core.Domain.Entities
;
using
Aurora.Core.Domain.Entities
;
using
Aurora.Domain.Entities
;
using
Aurora.Infrastructure.Tenant
;
using
Aurora.Infrastructure.Tenant
;
using
Aurora.Infrastructure.User
;
using
Aurora.Infrastructure.User
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore
;
...
@@ -18,16 +19,15 @@ namespace Aurora.Core.EntityFramework
...
@@ -18,16 +19,15 @@ namespace Aurora.Core.EntityFramework
{
{
public
class
ApplicationDbContext
:
DbContext
public
class
ApplicationDbContext
:
DbContext
{
{
private
readonly
I
CurrentUser
currentUser
;
private
readonly
I
UserContext
currentUser
;
private
readonly
I
CurrentTenan
t
currentTenant
;
private
readonly
I
TenantContex
t
currentTenant
;
public
ApplicationDbContext
(
DbContextOptions
<
ApplicationDbContext
>
options
)
:
base
(
options
)
public
ApplicationDbContext
(
DbContextOptions
<
ApplicationDbContext
>
options
,
IUserContextProvider
currentUserProvider
,
ITenantContextProvider
currentTenantProvider
)
:
base
(
options
)
{
{
// ,
currentUser
=
currentUserProvider
.
GetUserContext
();
// ICurrentUserProvider currentUserProvider,
currentTenant
=
currentTenantProvider
.
GetTenantContext
();
// ICurrentTenantProvider currentTenantProvider
// currentUser = currentUserProvider.GetCurrentUser();
// currentTenant = currentTenantProvider.GetCurrentTenant();
}
}
public
DbSet
<
Category
>
Categories
{
get
;
set
;
}
public
DbSet
<
Category
>
Categories
{
get
;
set
;
}
...
@@ -46,17 +46,19 @@ namespace Aurora.Core.EntityFramework
...
@@ -46,17 +46,19 @@ namespace Aurora.Core.EntityFramework
// 配置表名映射
// 配置表名映射
builder
.
Entity
<
Category
>().
ToTable
(
"category"
);
builder
.
Entity
<
Category
>().
ToTable
(
"category"
);
base
.
OnModelCreating
(
builder
);
base
.
OnModelCreating
(
builder
);
}
}
private
static
IList
<
Type
>
_baseEntityTypesCache
;
private
static
IList
<
Type
>
_baseEntityTypesCache
;
private
static
IList
<
Type
>
GetBaseEntityTypes
()
private
static
IList
<
Type
>
GetBaseEntityTypes
()
{
{
if
(
_baseEntityTypesCache
!=
null
)
if
(
_baseEntityTypesCache
!=
null
)
return
_baseEntityTypesCache
.
ToList
();
return
_baseEntityTypesCache
.
ToList
();
_baseEntityTypesCache
=
(
from
t
in
typeof
(
TenantEntityBase
).
GetTypeInfo
().
Assembly
.
DefinedTypes
var
assembly
=
typeof
(
TenantEntityBase
).
GetTypeInfo
().
Assembly
;
// var assembly=Assembly.Load("Aurora.Core.Domain");
_baseEntityTypesCache
=
(
from
t
in
assembly
.
DefinedTypes
where
t
.
BaseType
==
typeof
(
TenantEntityBase
)
where
t
.
BaseType
==
typeof
(
TenantEntityBase
)
select
t
.
AsType
()).
ToList
();
select
t
.
AsType
()).
ToList
();
return
_baseEntityTypesCache
;
return
_baseEntityTypesCache
;
...
...
Aurora.Micorservices/Aurora.Core/Aurora.Core.EntityFramework/ApplicationReadonlyDbContext.cs
浏览文件 @
6ab69f5b
...
@@ -10,6 +10,7 @@ using System.Threading;
...
@@ -10,6 +10,7 @@ using System.Threading;
using
System.Threading.Tasks
;
using
System.Threading.Tasks
;
using
Aurora.Common.Entities
;
using
Aurora.Common.Entities
;
using
Aurora.Core.Domain.Entities
;
using
Aurora.Core.Domain.Entities
;
using
Aurora.Domain.Entities
;
using
Aurora.Infrastructure.Tenant
;
using
Aurora.Infrastructure.Tenant
;
using
Aurora.Infrastructure.User
;
using
Aurora.Infrastructure.User
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore
;
...
@@ -18,16 +19,12 @@ namespace Aurora.Core.EntityFramework
...
@@ -18,16 +19,12 @@ namespace Aurora.Core.EntityFramework
{
{
public
class
ApplicationReadonlyDbContext
:
DbContext
public
class
ApplicationReadonlyDbContext
:
DbContext
{
{
private
readonly
ICurrentUser
currentUser
;
private
readonly
ITenantContext
currentTenant
;
private
readonly
ICurrentTenant
currentTenant
;
public
ApplicationReadonlyDbContext
(
DbContextOptions
<
ApplicationReadonlyDbContext
>
options
)
:
base
(
options
)
public
ApplicationReadonlyDbContext
(
DbContextOptions
<
ApplicationReadonlyDbContext
>
options
,
ITenantContextProvider
currentTenantProvider
)
:
base
(
options
)
{
{
// ,
currentTenant
=
currentTenantProvider
.
GetTenantContext
();
// ICurrentUserProvider currentUserProvider,
// ICurrentTenantProvider currentTenantProvider
// currentUser = currentUserProvider.GetCurrentUser();
// currentTenant = currentTenantProvider.GetCurrentTenant();
}
}
public
DbSet
<
Category
>
Categories
{
get
;
set
;
}
public
DbSet
<
Category
>
Categories
{
get
;
set
;
}
...
@@ -56,12 +53,14 @@ namespace Aurora.Core.EntityFramework
...
@@ -56,12 +53,14 @@ namespace Aurora.Core.EntityFramework
{
{
if
(
_baseEntityTypesCache
!=
null
)
if
(
_baseEntityTypesCache
!=
null
)
return
_baseEntityTypesCache
.
ToList
();
return
_baseEntityTypesCache
.
ToList
();
_baseEntityTypesCache
=
(
from
t
in
typeof
(
TenantEntityBase
).
GetTypeInfo
().
Assembly
.
DefinedTypes
var
assembly
=
typeof
(
TenantEntityBase
).
GetTypeInfo
().
Assembly
;
// var assembly=Assembly.Load("Aurora.Core.Domain");
_baseEntityTypesCache
=
(
from
t
in
assembly
.
DefinedTypes
where
t
.
BaseType
==
typeof
(
TenantEntityBase
)
where
t
.
BaseType
==
typeof
(
TenantEntityBase
)
select
t
.
AsType
()).
ToList
();
select
t
.
AsType
()).
ToList
();
return
_baseEntityTypesCache
;
return
_baseEntityTypesCache
;
}
}
protected
static
readonly
MethodInfo
SetGlobalQueryMethod
=
typeof
(
ApplicationDbContext
).
GetMethods
(
BindingFlags
.
Public
|
BindingFlags
.
Instance
)
protected
static
readonly
MethodInfo
SetGlobalQueryMethod
=
typeof
(
Application
Readonly
DbContext
).
GetMethods
(
BindingFlags
.
Public
|
BindingFlags
.
Instance
)
.
Single
(
t
=>
t
.
IsGenericMethod
&&
t
.
Name
==
"SetGlobalQuery"
);
.
Single
(
t
=>
t
.
IsGenericMethod
&&
t
.
Name
==
"SetGlobalQuery"
);
public
void
SetGlobalQuery
<
T
>(
ModelBuilder
builder
)
where
T
:
TenantEntityBase
public
void
SetGlobalQuery
<
T
>(
ModelBuilder
builder
)
where
T
:
TenantEntityBase
...
...
Thinking.md
0 → 100644
浏览文件 @
6ab69f5b
# 记录一些想法和思考
## 接口日志如何实现
可以记录操作路径,参数,业务类型,业务描述的
*
后端接口过滤器
*
统一的日志中间件(程序中的中间件,或者 类似网关的日志中间件)
*
前端埋点 ?
scripts/category.sql
浏览文件 @
6ab69f5b
...
@@ -23,6 +23,7 @@ SET FOREIGN_KEY_CHECKS = 0;
...
@@ -23,6 +23,7 @@ SET FOREIGN_KEY_CHECKS = 0;
DROP
TABLE
IF
EXISTS
`category`
;
DROP
TABLE
IF
EXISTS
`category`
;
CREATE
TABLE
`category`
(
CREATE
TABLE
`category`
(
`Id`
int
NOT
NULL
AUTO_INCREMENT
,
`Id`
int
NOT
NULL
AUTO_INCREMENT
,
`parentId`
int
NULL
,
`name`
varchar
(
255
)
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_unicode_ci
NOT
NULL
,
`name`
varchar
(
255
)
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_unicode_ci
NOT
NULL
,
`remark`
varchar
(
255
)
COLLATE
utf8mb4_unicode_ci
DEFAULT
NULL
,
`remark`
varchar
(
255
)
COLLATE
utf8mb4_unicode_ci
DEFAULT
NULL
,
`createTime`
datetime
NOT
NULL
,
`createTime`
datetime
NOT
NULL
,
...
@@ -34,3 +35,4 @@ CREATE TABLE `category` (
...
@@ -34,3 +35,4 @@ CREATE TABLE `category` (
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_unicode_ci
;
)
ENGINE
=
InnoDB
DEFAULT
CHARSET
=
utf8mb4
COLLATE
=
utf8mb4_unicode_ci
;
SET
FOREIGN_KEY_CHECKS
=
1
;
SET
FOREIGN_KEY_CHECKS
=
1
;
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录