Galosys.Foundation.Authorization.EntityFrameworkCore 26.8.12.2

dotnet add package Galosys.Foundation.Authorization.EntityFrameworkCore --version 26.8.12.2
                    
NuGet\Install-Package Galosys.Foundation.Authorization.EntityFrameworkCore -Version 26.8.12.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Galosys.Foundation.Authorization.EntityFrameworkCore" Version="26.8.12.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.Authorization.EntityFrameworkCore" Version="26.8.12.2" />
                    
Directory.Packages.props
<PackageReference Include="Galosys.Foundation.Authorization.EntityFrameworkCore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Galosys.Foundation.Authorization.EntityFrameworkCore --version 26.8.12.2
                    
#r "nuget: Galosys.Foundation.Authorization.EntityFrameworkCore, 26.8.12.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Galosys.Foundation.Authorization.EntityFrameworkCore@26.8.12.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Galosys.Foundation.Authorization.EntityFrameworkCore&version=26.8.12.2
                    
Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.Authorization.EntityFrameworkCore&version=26.8.12.2
                    
Install as a Cake Tool

Galosys.Foundation.Authorization.EntityFrameworkCore

基于 EF Core 的 ABAC/RBAC 策略存储包:为 Galosys.Foundation.Authorization 提供数据库版只读策略仓库,适配服务无既有 RBAC 表的应用(静态存储模式)。策略以 JSON 单列存储,评估路径全量读入内存。

设计文档:docs/designs/abac-design.md(§4.2 静态存储模式、§6.6 authz_* 迁移表)。核心接口见 Galosys.Foundation.Authorization

表结构

实体 说明
AuthzPolicy authz_policy 策略(雪花 Id、Name 唯一=权限码、Content 策略 JSON、Version 行级版本)
AuthzPrincipalPolicy authz_principal_policy 主体↔策略绑定(PrincipalType/PrincipalId/PolicyName)
AuthzRoleAssignment authz_role_assignment 用户↔角色(UserId/RoleName)
AuthzRoleHierarchy authz_role_hierarchy 角色继承(ParentRole/ChildRole/TenantId)
AuthzResource authz_resource 资源定义(Code=ARN 唯一)

五实体均继承 FullEntity<long>(审计列 + 软删除);唯一索引经 IEntityTypeConfiguration<> 提供,DbContext<T> 自动发现——宿主自带上下文同样生效。

用法

本包不定义自己的 DbContext(对齐 Actuator/Outbox 惯例),宿主需自行注册 DbContext<T> 上下文。

使用宿主自带的上下文

仓储与 DI 均为泛型(TContext : DbContext<TContext>),宿主把自有的 DbContext<T> 塞进来即可,[Table] 实体与配置类会被自动发现:

services.AddDbContext<MyContext>(options => ...);
services.AddAuthorizationEngineEfCore<MyContext>();

对齐 AddActuatorEFCore<TContext> / AddEfCoreOutboxStore<TDbContext> 惯例:无自动装配模块,需宿主显式调用泛型扩展。

热更新组合

仓储不内建缓存,配合核心包 PolicyCache 实现版本号轮询热更新:

services.TryAddSingleton<IAuthorizationPolicyRepository>(sp =>
{
    var inner = sp.GetRequiredService<IAuthorizationPolicyRepository>(); // EfCoreAuthorizationPolicyRepository
    var logger = sp.GetRequiredService<ILogger<PolicyCache>>();
    return new PolicyCache(inner, TimeSpan.FromSeconds(30), logger);
});

依赖

  • Galosys.Foundation.Authorization / Galosys.Foundation.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore / Microsoft.EntityFrameworkCore.Relational

测试

测试项目使用内存 Sqlite(SqliteConnection("DataSource=:memory:") + EnsureCreated()),覆盖仓储全方法与角色继承/租户过滤。

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
26.8.12.2 0 8/12/2026
26.8.12.1 0 8/12/2026
26.8.10.1 46 8/10/2026
26.8.5.1 57 8/5/2026
26.8.4.1 57 8/4/2026