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
                    
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="EasyDDD.Repository.Redis" Version="4.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EasyDDD.Repository.Redis" Version="4.0.0" />
                    
Directory.Packages.props
<PackageReference Include="EasyDDD.Repository.Redis" />
                    
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 EasyDDD.Repository.Redis --version 4.0.0
                    
#r "nuget: EasyDDD.Repository.Redis, 4.0.0"
                    
#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 EasyDDD.Repository.Redis@4.0.0
                    
#: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=EasyDDD.Repository.Redis&version=4.0.0
                    
Install as a Cake Addin
#tool nuget:?package=EasyDDD.Repository.Redis&version=4.0.0
                    
Install as a Cake Tool
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 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. 
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
4.0.0 481 3/26/2025
3.0.3 355 7/1/2024
3.0.2 164 3/6/2024
3.0.1 980 12/4/2023
3.0.0 202 11/29/2023
2.3.3 202 11/22/2023
2.2.0 355 10/7/2023
2.1.2 1,016 5/4/2023
2.1.0 643 3/10/2022
2.0.14 664 2/24/2022
2.0.12 833 2/14/2022
2.0.10 531 1/20/2022
2.0.4 951 12/1/2021
2.0.3 494 10/25/2021
2.0.1 460 9/26/2021
2.0.0 464 8/9/2021
1.9.1 451 7/23/2021
1.9.0 427 7/23/2021
1.7.0 487 5/15/2021
1.6.7 549 1/11/2021
1.6.6 484 1/11/2021
1.6.5 536 1/5/2021
1.6.4 546 12/30/2020
1.6.3 529 12/17/2020
1.6.2 574 12/11/2020
1.6.1 524 12/10/2020
1.6.0 561 12/10/2020
1.5.10 529 11/17/2020
1.5.9 525 11/13/2020
1.5.8 577 11/13/2020
1.5.7 560 11/13/2020
1.5.6 568 11/13/2020
1.5.5 574 11/13/2020
1.5.4 595 11/6/2020
1.5.3 529 11/6/2020
1.5.2 555 11/6/2020
1.5.0 564 11/6/2020
1.4.0 563 11/5/2020
1.3.0 570 11/3/2020
1.1.0 630 5/8/2020