MasLazu.AspNet.Authorization.Core.EfCore
1.0.0-preview.7
dotnet add package MasLazu.AspNet.Authorization.Core.EfCore --version 1.0.0-preview.7
NuGet\Install-Package MasLazu.AspNet.Authorization.Core.EfCore -Version 1.0.0-preview.7
<PackageReference Include="MasLazu.AspNet.Authorization.Core.EfCore" Version="1.0.0-preview.7" />
<PackageVersion Include="MasLazu.AspNet.Authorization.Core.EfCore" Version="1.0.0-preview.7" />
<PackageReference Include="MasLazu.AspNet.Authorization.Core.EfCore" />
paket add MasLazu.AspNet.Authorization.Core.EfCore --version 1.0.0-preview.7
#r "nuget: MasLazu.AspNet.Authorization.Core.EfCore, 1.0.0-preview.7"
#:package MasLazu.AspNet.Authorization.Core.EfCore@1.0.0-preview.7
#addin nuget:?package=MasLazu.AspNet.Authorization.Core.EfCore&version=1.0.0-preview.7&prerelease
#tool nuget:?package=MasLazu.AspNet.Authorization.Core.EfCore&version=1.0.0-preview.7&prerelease
MasLazu.AspNet.Authorization.Core.EfCore
This project provides the Entity Framework Core implementation for the MasLazu ASP.NET Authorization system. It configures the database context, entity mappings, relationships, and provides the data access layer for the authorization domain.
Overview
The EF Core layer serves as the data access component, translating domain entities into database tables and managing relationships between authorization entities. It uses Entity Framework Core to provide efficient querying, change tracking, and database operations.
Architecture
EF Core Layer
├── Data/ # Database context
├── Configurations/ # Entity type configurations
└── Extensions/ # Dependency injection setup
Database Context
AuthorizationCoreDbContext
The main database context inheriting from BaseDbContext:
public class AuthorizationCoreDbContext : BaseDbContext
{
public AuthorizationCoreDbContext(DbContextOptions<AuthorizationCoreDbContext> options) : base(options)
{
}
public DbSet<Permission> Permissions { get; set; }
public DbSet<PermissionType> PermissionTypes { get; set; }
public DbSet<Resource> Resources { get; set; }
public DbSet<ResourceAction> ResourceActions { get; set; }
public DbSet<Domain.Entities.Action> Actions { get; set; }
}
Entity Configurations
Each domain entity has a corresponding configuration class implementing IEntityTypeConfiguration<TEntity>:
ActionConfiguration
- Primary key:
Id - Required properties:
Code(50 chars),Name(100 chars) - Unique index on
Code
PermissionConfiguration
- Primary key:
Id - Required properties:
Code(100 chars),Name(100 chars),Description(500 chars),TypeCode(10 chars) - Unique index on
Code
PermissionTypeConfiguration
- Primary key:
Id - Required properties:
Code(50 chars),Description(200 chars) - Unique index on
Code
ResourceConfiguration
- Primary key:
Id - Required properties:
Code(50 chars),Name(100 chars) - Unique index on
Code
ResourceActionConfiguration
Complex configuration for the junction entity:
- Primary key:
Id - Required properties:
PermissionCode,ResourceCode,ActionCode - Foreign key relationships:
ResourceviaResourceCode→Resource.CodeActionviaActionCode→Action.CodePermissionviaPermissionCode→Permission.Code
- Cascade delete behavior
- Unique index on
PermissionCode - Composite index on
(ResourceCode, ActionCode)
Database Schema
The configurations create the following table structure:
Actions
├── Id (PK)
├── Code (UQ, 50)
├── Name (100)
├── CreatedAt
└── UpdatedAt
Permissions
├── Id (PK)
├── Code (UQ, 100)
├── Name (100)
├── Description (500)
├── TypeCode (10)
├── CreatedAt
└── UpdatedAt
PermissionTypes
├── Id (PK)
├── Code (UQ, 50)
├── Description (200)
├── CreatedAt
└── UpdatedAt
Resources
├── Id (PK)
├── Code (UQ, 50)
├── Name (100)
├── CreatedAt
└── UpdatedAt
ResourceActions
├── Id (PK)
├── PermissionCode (FK → Permissions.Code, UQ)
├── ResourceCode (FK → Resources.Code)
├── ActionCode (FK → Actions.Code)
├── CreatedAt
├── UpdatedAt
└── IX: (ResourceCode, ActionCode)
Relationships
The entity configurations establish the following relationships:
- ResourceAction → Permission: Many-to-one via
PermissionCode - ResourceAction → Resource: Many-to-one via
ResourceCode - ResourceAction → Action: Many-to-one via
ActionCode
All relationships use cascade delete, meaning deleting a Permission/Resource/Action will remove associated ResourceActions.
Key Design Decisions
Code-Based Foreign Keys
Unlike typical EF Core setups using Id-based foreign keys, this implementation uses Code-based relationships:
- Allows for more readable and meaningful foreign key values
- Supports business logic based on codes rather than surrogate keys
- Requires unique constraints on Code fields
Unique Constraints
- All entity Codes have unique indexes
- PermissionCode in ResourceActions is unique (one permission per resource-action combination)
- Composite index on (ResourceCode, ActionCode) for efficient queries
Dependencies
This project depends on:
MasLazu.AspNet.Authorization.Core.Domain- Domain entitiesMicrosoft.EntityFrameworkCore- EF Core ORMMasLazu.AspNet.Framework.EfCore- Base context and framework components
Usage
Database Context Registration
services.AddDbContext<AuthorizationCoreDbContext>(options =>
options.UseSqlServer(connectionString));
Migration and Database Setup
// Generate migration
dotnet ef migrations add InitialCreate --project src/MasLazu.AspNet.Authorization.Core.EfCore
// Apply migration
dotnet ef database update --project src/MasLazu.AspNet.Authorization.Core.EfCore
Repository Pattern Integration
The DbContext integrates with the repository pattern through:
IRepository<TEntity>implementationsIUnitOfWorkfor transaction managementIReadRepository<TEntity>for read operations
Integration
This EF Core project integrates with:
- Domain Layer: Maps domain entities to database tables
- Core Layer: Provides data access for service implementations
- Application Layer: Supports business operations with transactional data access
The EF Core layer ensures efficient data persistence while maintaining the domain model's integrity and relationships.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net9.0
- FastEndpoints (>= 7.0.1)
- FluentValidation (>= 12.0.0)
- MasLazu.AspNet.Authorization.Core.Domain (>= 1.0.0-preview.7)
- MasLazu.AspNet.Framework.Application (>= 1.0.0-preview.15)
- MasLazu.AspNet.Framework.Domain (>= 1.0.0-preview.15)
- MasLazu.AspNet.Framework.EfCore (>= 1.0.0-preview.15)
- Microsoft.EntityFrameworkCore (>= 9.0.9)
- Microsoft.Extensions.DependencyInjection (>= 9.0.9)
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 |
|---|---|---|
| 1.0.0-preview.7 | 138 | 10/9/2025 |
| 1.0.0-preview.6 | 128 | 10/9/2025 |
| 1.0.0-preview.5 | 128 | 10/9/2025 |
| 1.0.0-preview.1 | 171 | 9/20/2025 |