EasyDDD.Repository.Redis
4.0.0
dotnet add package EasyDDD.Repository.Redis --version 4.0.0
NuGet\Install-Package EasyDDD.Repository.Redis -Version 4.0.0
<PackageReference Include="EasyDDD.Repository.Redis" Version="4.0.0" />
<PackageVersion Include="EasyDDD.Repository.Redis" Version="4.0.0" />
<PackageReference Include="EasyDDD.Repository.Redis" />
paket add EasyDDD.Repository.Redis --version 4.0.0
#r "nuget: EasyDDD.Repository.Redis, 4.0.0"
#:package EasyDDD.Repository.Redis@4.0.0
#addin nuget:?package=EasyDDD.Repository.Redis&version=4.0.0
#tool nuget:?package=EasyDDD.Repository.Redis&version=4.0.0
How to Use
安装包
提供EF和Mongo两个数据库包分别为
dotnet add package EasyDDD.Repository.EF --version 4.0.0
和
dotnet add package EasyDDD.Repository.Mongo --version 4.0.0
同时提供一个缓存包,在需要使用缓存时安装
dotnet add package EasyDDD.Repository.Redis --version 4.0.0
服务注册
AddEasyDDD()是必须的,如果提供了参数注册时会自动扫描相应程序集注册对应服务,并同时将程序集提交给Automapper和MediatR 视安装的包使用UseEF()、UseMongo()、UseRedis()
services.AddEasyDDD(typeof(Startup).Assembly).UseEF().UseMongo().UseRedis();
实体
必须继承Entity<K>或者EntityEx<K>,K为主键,因兼容Mongo所以不支持联合主键 继承EntityEx<K>会自动添加创建时间 创建人 删除时间 是否删除 最后更新时间 几个属性,会自动管理这些属性值
public class Demo:Entity<int>
{
pubcli Demo(int id):base(id){}
}
DbContext
相关数据上下文,如果在注册时提供了程序集会自动注入服务
public class EFContext : EasyDDD.EF.BaseContext
{
private readonly IConfiguration configuration;
public EFContext(IConfiguration configuration){this.configuration = configuration;}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder){}
protected override void OnModelCreating(ModelBuilder modelBuilder){}
}
or
public class MongoContext : EasyDDD.Mongo.UnitOfWork
{
public MongoContext(IConfiguration configuration) : base(configuration){}
public override string DataBaseName => "XXXXXX";
public override string MongoConfiguration => "mongo";
}
or
public class RedisContext : Redis.UnitOfWork
{
public RedisContext(IConfiguration configuration) : base(configuration) { }
public virtual string RedisConfiguration => "redis";
}
对于EF和Mongo如果只有一个Context,则在使用时会直接使用,如果有多个Context,在使用泛型的仓储或者Service时则按注入顺序选择最后一个 注入顺序可在Context上添加DefaultContextAttribute特性标识顺序 如果有多个实体且每个实体对应各不同的Context,则可实现IContextComponent,为每个实体返回特定的Context
public class ContextComponent : DefaultContextComponent
{
public override Type Match<T>()
{
return typeof(EasyDDD.Test.Context.EFContext);
}
}
Repository
默认注入了泛型仓储IRepository<,>、IEFRepository<,>、IMongoRepository<,>可直接使用,也可自定义实现
public interface IEFEntityRepository<T, K> : IEFRepository<T, K> where T : Entity<K>
public class EFEntityRepository<T, K> : EFRepository<T, K>, IEFEntityRepository<T, K> where T : Entity<K>
{
public EFEntityRepository(IServiceProvider provider) : base(provider) { }
}
public interface IDemoEFRepository : IEFRepository<Demo, int>{}
public class DemoEFRepository : EFRepository<Demo, int>, IDemoEFRepository
{
public DemoEFRepository(IServiceProvider context) : base(context) { }
}
如果在服务注册时提供了所在程序集,则IEFEntityRepository<>和IDemoEFRepository会自动注入,都可直接使用
Cache
在Domain实体上添加CacheAttribute特性,会激活实体的缓存功能,需要使用Redis包,否则不起作用 实体启用缓存后在仓储的方法中默认会使用缓存,如不实用在方法参数中useCache传false
Service
默认注入了IService<T, K> ,IService<T, K, DTO>,IService<T, K, DTO, AddOrUpdateEntity>,IService<T, K, DTO, AddEntity, UpdateEntity>服务,可直接使用
基于MediatR注入了AddRequestHandler<T, K, AddEntity>、DeleteRequestHandler<T, K>、QueryRequest<T, K, Query>、QueryRequest<T, K, Query, DTO>、UpdateRequestHandler<T, K, UpdateEntity> 可直接使用泛型的MediatR RequestHandler,对应的Request为AddRequest<T, K, AddEntity>、 DeleteRequest<T, K>、 QueryRequest<T, K, Query>、QueryRequest<T, K, Query, DTO>、UpdateRequest<T, K, UpdateEntity> 使用方式
mediator.Send(new QueryRequest<Demo, int, QueryDemo>(new QueryDemo { }));
public interface IDemoService:IBaseService<Demo,string>{}
public class DemoService : BaseService<Demo, string>,IDemoService
{
public DemoService(IDemoEFRepository repository) : base(repository) { }
}
Event
基于MediatR提供事件发布, 事件数据
public class AddNodeData : EventData
{
public string NodeName { get; set; }
}
public class AddNodeHandler : BaseEventHandler<AddNodeData>
{
public override async Task HandleEvent(AddNodeData eventData){
return;
}
}
在实体中提供有AddEvent(EventData)方法,在实体提交数据库成功后会发布事件
Controller
public class ValuesController : ControllerBase
{
private IDemoService service;
private readonly IService<Demo, int, DemoDTO> efService;
private readonly IMediator mediator;
public ValuesController(IDemoService service,IService<Demo, int, DemoDTO> efService,IMediator mediator){
this.service = service;
this.efService = efService;
this.mediator = mediator;
}
public void Get(){
service.Find...
service.Insert...
service.Update...
service.Delete...
await mediator.Send(new QueryRequest<Demo, int, QueryDemo>(new QueryDemo { }));
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- EasyDDD.Core (>= 4.0.0)
- Newtonsoft.Json (>= 13.0.1)
- StackExchange.Redis (>= 2.0.495)
-
net5.0
- EasyDDD.Core (>= 4.0.0)
- Newtonsoft.Json (>= 13.0.1)
- StackExchange.Redis (>= 2.2.3)
-
net6.0
- EasyDDD.Core (>= 4.0.0)
- Newtonsoft.Json (>= 13.0.1)
- StackExchange.Redis (>= 2.2.3)
-
net7.0
- EasyDDD.Core (>= 4.0.0)
- Newtonsoft.Json (>= 13.0.1)
- StackExchange.Redis (>= 2.2.3)
-
net8.0
- EasyDDD.Core (>= 4.0.0)
- Newtonsoft.Json (>= 13.0.1)
- StackExchange.Redis (>= 2.2.3)
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 |
---|---|---|
4.0.0 | 481 | 3/26/2025 |
3.0.3 | 356 | 7/1/2024 |
3.0.2 | 165 | 3/6/2024 |
3.0.1 | 982 | 12/4/2023 |
3.0.0 | 204 | 11/29/2023 |
2.3.3 | 204 | 11/22/2023 |
2.2.0 | 357 | 10/7/2023 |
2.1.2 | 1,020 | 5/4/2023 |
2.1.0 | 645 | 3/10/2022 |
2.0.14 | 665 | 2/24/2022 |
2.0.12 | 833 | 2/14/2022 |
2.0.10 | 532 | 1/20/2022 |
2.0.4 | 953 | 12/1/2021 |
2.0.3 | 494 | 10/25/2021 |
2.0.1 | 462 | 9/26/2021 |
2.0.0 | 466 | 8/9/2021 |
1.9.1 | 453 | 7/23/2021 |
1.9.0 | 428 | 7/23/2021 |
1.7.0 | 489 | 5/15/2021 |
1.6.7 | 549 | 1/11/2021 |
1.6.6 | 485 | 1/11/2021 |
1.6.5 | 538 | 1/5/2021 |
1.6.4 | 547 | 12/30/2020 |
1.6.3 | 531 | 12/17/2020 |
1.6.2 | 576 | 12/11/2020 |
1.6.1 | 524 | 12/10/2020 |
1.6.0 | 561 | 12/10/2020 |
1.5.10 | 531 | 11/17/2020 |
1.5.9 | 527 | 11/13/2020 |
1.5.8 | 579 | 11/13/2020 |
1.5.7 | 562 | 11/13/2020 |
1.5.6 | 568 | 11/13/2020 |
1.5.5 | 576 | 11/13/2020 |
1.5.4 | 597 | 11/6/2020 |
1.5.3 | 531 | 11/6/2020 |
1.5.2 | 557 | 11/6/2020 |
1.5.0 | 566 | 11/6/2020 |
1.4.0 | 565 | 11/5/2020 |
1.3.0 | 572 | 11/3/2020 |
1.1.0 | 631 | 5/8/2020 |