Aura.Framework
1.0.2
dotnet add package Aura.Framework --version 1.0.2
NuGet\Install-Package Aura.Framework -Version 1.0.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="Aura.Framework" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Aura.Framework" Version="1.0.2" />
<PackageReference Include="Aura.Framework" />
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 Aura.Framework --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Aura.Framework, 1.0.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 Aura.Framework@1.0.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=Aura.Framework&version=1.0.2
#tool nuget:?package=Aura.Framework&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Aura Framework
一个基于 .NET 8 的轻量级、模块化开发框架,提供了模块化架构模式的实现,集成了 Autofac 依赖注入容器和 AutoMapper 对象映射,帮助开发者快速构建应用。
🚀 特性
- 模块化架构: 基于 Autofac 的模块化系统,支持模块依赖管理
- CRUD 操作: 开箱即用的 CRUD 应用服务基类
- 雪花算法 ID 生成: 分布式唯一 ID 生成器
- 依赖注入: 基于 Autofac 的高级依赖注入功能
- 生命周期管理: 支持 Singleton、Scoped、Transient 三种生命周期
- 单元测试支持: 提供集成测试基类
- 缓存管理: 内置缓存管理器
- Entity Framework 集成: 完整的 Repository 模式实现
📦 项目结构
Aura/
├── Aura.Common/ # 公共组件和工具类
├── Aura.Domain/ # 领域层:实体、仓储接口
├── Aura.Application/ # 应用层:应用服务
├── Aura.Modularity/ # 模块化框架核心
└── Aura.Testing/ # 测试基础设施
🛠️ 安装
通过 NuGet 安装
# 安装核心包
Install-Package Aura.Common
Install-Package Aura.Domain
Install-Package Aura.Application
Install-Package Aura.Modularity
# 安装测试包(可选)
Install-Package Aura.Testing
通过 .NET CLI 安装
dotnet add package Aura.Common
dotnet add package Aura.Domain
dotnet add package Aura.Application
dotnet add package Aura.Modularity
🏗️ 快速开始
1. 创建领域实体
using Aura.Domain;
public class User : Entity<long>
{
public string Name { get; set; }
public string Email { get; set; }
}
2. 创建应用服务
using Aura.Application.Services;
using Aura.Common;
public class UserAppService : CrudAppServiceImp<User, long, UserDto, UserQueryConditionDto>
{
public UserAppService(IRepository<User, long> repository, IMapper mapper, SnowflakeIdGenerator idGenerator)
: base(repository, mapper, idGenerator)
{
}
}
public class UserDto
{
public long Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
}
public class UserQueryConditionDto : BasicEntityQueryConditionDto<long>
{
public string Name { get; set; }
}
3. 创建模块
using Aura.Modularity;
using Aura.Modularity.Attributes;
using Microsoft.Extensions.DependencyInjection;
[LifetimeAttribute(LifetimeEnum.Scoped)]
public class UserModule : AuraModule
{
protected override void ConfigureService(IServiceCollection services)
{
services.AddSnowflakeIdGenerator();
// 注册其他服务
}
}
4. 启动应用
var factory = new AuraModuleServiceProvideFactory();
var builder = factory.CreateBuilderByModule<UserModule>();
var serviceProvider = factory.CreateServiceProvider(builder);
// 使用服务
var userService = serviceProvider.GetService<UserAppService>();
📋 核心组件
模块化系统
Aura Framework 的模块化系统基于 Autofac,支持:
- 模块依赖: 使用
[DependentModule]特性声明模块依赖 - 生命周期管理: 使用
[Lifetime]特性控制服务生命周期 - 自动注册: 自动扫描和注册程序集中的服务
[DependentModule(typeof(CommonModule))]
[LifetimeAttribute(LifetimeEnum.Scoped)]
public class BusinessModule : AuraModule
{
protected override void ConfigureService(IServiceCollection services)
{
// 配置服务
}
}
CRUD 应用服务
提供完整的 CRUD 操作基类:
// 查询操作
var entity = await userService.GetByIdAsync(id);
var entities = await userService.GetListAsync();
// 创建操作
await userService.InsertSingleAsync(userDto);
// 更新操作
await userService.UpdateByIdAsync(id, userDto);
// 删除操作(软删除)
await userService.DeleteByIdAsync(id);
雪花算法 ID 生成器
分布式唯一 ID 生成:
var idGenerator = new SnowflakeIdGenerator(workerId: 1, datacenterId: 1);
var id = idGenerator.NextId(); // 生成 long 类型 ID
var typedId = idGenerator.NextId<long>(); // 生成指定类型 ID
仓储模式
完整的 Repository 模式实现:
public interface IRepository<TEntity, Tkey> where TEntity : Entity<Tkey> where Tkey : struct
{
IQueryable<TEntity> Where(Expression<Func<TEntity, bool>> predicate);
IQueryable<TEntity> WhereByNoTracking(Expression<Func<TEntity, bool>> predicate);
Task<TEntity> InsertAsync(TEntity entity);
void Update(TEntity entity);
void Delete(TEntity entity);
void SoftDelete(TEntity entity);
Task SaveAsync();
}
工具类和扩展
- LINQ 扩展: 条件查询扩展方法
- 缓存管理: 内存缓存管理器
- 服务响应: 统一的服务响应模型
// LINQ 条件扩展
var query = dbContext.Users.WhereIf(!string.IsNullOrEmpty(name), u => u.Name.Contains(name));
// 服务响应
public async Task<ServiceResponse<UserDto>> GetUserAsync(long id)
{
var user = await userService.GetByIdAsync(id);
return user != null
? ServiceResponse<UserDto>.Success(user)
: ServiceResponse<UserDto>.Fail("用户不存在");
}
🧪 单元测试
使用 Aura.Testing 进行集成测试:
public class UserServiceTests : AuraIntegratedTest<UserModule>
{
[Test]
public async Task Should_Create_User_Successfully()
{
// Arrange
var userService = GetRequiredService<UserAppService>();
var userDto = new UserDto { Name = "Test User", Email = "test@example.com" };
// Act
await userService.InsertSingleAsync(userDto);
// Assert
var users = await userService.GetListAsync();
Assert.That(users.Count, Is.GreaterThan(0));
}
}
📚 高级特性
属性标记
[BlockModify]: 标记属性在更新时不可修改[NavigationEntity]: 标记导航属性,在 CRUD 操作时特殊处理[Lifetime]: 控制服务生命周期[DependentModule]: 声明模块依赖关系
查询条件 DTO
框架提供了基础查询条件类:
public class BasicEntityQueryConditionDto<T>
{
public T? Id { get; set; }
public bool? IsDeleted { get; set; } = false;
}
public class BasicListQueryConditionDto<T> : BasicEntityQueryConditionDto<T>
{
public DateTime? StartCreateTime { get; set; }
public DateTime? EndCreateTime { get; set; }
public int? PageSize { get; set; }
public int PageNum { get; set; }
}
🔧 配置选项
雪花算法配置
services.AddSnowflakeIdGenerator(); // 使用默认配置 (1, 1)
// 或自定义配置
services.AddSingleton<SnowflakeIdGenerator>(_ =>
new SnowflakeIdGenerator(workerId: 2, datacenterId: 3));
模块配置
public class MyModule : AuraModule
{
protected override void ConfigureService(IServiceCollection services)
{
// 注册 AutoMapper 配置
services.AddAutoMapper(typeof(MyMappingProfile));
// 注册其他服务
services.AddScoped<IMyService, MyService>();
}
}
🎯 最佳实践
- 模块化设计: 按业务领域划分模块,保持模块间的低耦合
- DTO 映射: 使用 AutoMapper 进行实体和 DTO 之间的映射
- 异步编程: 优先使用异步方法进行数据库操作
- 软删除: 使用软删除而非物理删除来保护数据
- 单元测试: 为每个应用服务编写完整的单元测试
🤝 贡献
欢迎提交 Issue 和 Pull Request 来改进这个框架。
📄 许可证
本项目基于 MIT 许可证开源 - 查看 LICENSE 文件了解详情。
📞 支持
如果你在使用过程中遇到问题,可以:
- 查看文档和示例代码
- 提交 Issue 描述问题
- 参与讨论和交流
🗺️ 版本路线图
- 添加更多数据库支持
- 集成消息队列
- 添加分布式缓存支持
- 提供更多单元测试工具
- 性能优化和监控
Aura Framework - 让 .NET 开发更简单、更高效!
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Autofac (>= 8.2.0)
- Autofac.Extensions.DependencyInjection (>= 10.0.0)
- AutoMapper (>= 13.0.1)
- Microsoft.EntityFrameworkCore (>= 8.0.16)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
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.2 | 175 | 6/7/2025 |
v1.0.2 - 初始版本
- 模块化架构支持
- 模块分层架构
- CRUD 应用服务基类
- 雪花算法 ID 生成器
- Repository 模式实现
- 单元测试支持
- 缓存管理器