LightPoint.Foundation.Specification.EFCore 1.3.5.9

dotnet add package LightPoint.Foundation.Specification.EFCore --version 1.3.5.9
                    
NuGet\Install-Package LightPoint.Foundation.Specification.EFCore -Version 1.3.5.9
                    
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="LightPoint.Foundation.Specification.EFCore" Version="1.3.5.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LightPoint.Foundation.Specification.EFCore" Version="1.3.5.9" />
                    
Directory.Packages.props
<PackageReference Include="LightPoint.Foundation.Specification.EFCore" />
                    
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 LightPoint.Foundation.Specification.EFCore --version 1.3.5.9
                    
#r "nuget: LightPoint.Foundation.Specification.EFCore, 1.3.5.9"
                    
#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 LightPoint.Foundation.Specification.EFCore@1.3.5.9
                    
#: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=LightPoint.Foundation.Specification.EFCore&version=1.3.5.9
                    
Install as a Cake Addin
#tool nuget:?package=LightPoint.Foundation.Specification.EFCore&version=1.3.5.9
                    
Install as a Cake Tool

简要说明

LightPoint.Foundation.Specification.EFCore 是项目 LightPoint.Foundation.Specification 在 EF Core 中的应用。

本项目是参考 Steve Smith 的 Specification 的项目来具体实现的。

LpEFRepositoryBase.cs 和 LpEFContextFactoryRepositoryBase.cs 都是实现了仓储模式的基类,用于抽象化对实体框架(Entity Framework)的操作,但它们在实现和使用场景上有所不同。

相同点

  1. 功能性:两者都提供了一系列异步方法来处理实体的增删改查(CRUD)操作,例如 AddAsync, UpdateAsync, DeleteAsync 等。
  2. 规范应用:它们都使用了规范(Specification)模式来构建查询,允许更灵活地定义查询逻辑。
  3. 泛型设计:两个基类都采用了泛型设计,允许对不同的实体类型进行操作。

不同点

  1. 上下文管理:
    • LpEFRepositoryBase 直接持有一个 DbContext 实例。这意味着它依赖于直接的 DbContext 注入,适用于生命周期较短的场景,如一次性的 Web 请求。
    • LpEFContextFactoryRepositoryBase 通过 IDbContextFactory 来创建 DbContext 实例。这种方式允许在需要时创建新的 DbContext 实例,更适合于生命周期较长的应用场景,如 Blazor 服务器端应用或其他需要长时间运行的情况。
  2. 使用场景:
    • LpEFRepositoryBase 适用于生命周期管理相对简单的应用场景,如传统的 ASP.NET Core Web 应用,其中每个请求都是独立的,并且请求结束时可以释放 DbContext。
    • LpEFContextFactoryRepositoryBase 适用于需要更细粒度控制 DbContext 生命周期的场景,特别是在 Blazor 或其他长时间运行的应用中。通过 IDbContextFactory,它可以为每个工作单元或操作创建新的 DbContext 实例,从而避免了因长时间持有单个 DbContext 实例而导致的潜在内存泄漏和数据一致性问题。

总结

  • 如果你的应用是基于请求的,每个请求相对独立,并且对于每个请求,DbContext 的生命周期很短,那么使用 LpEFRepositoryBase 就足够了。
  • 如果你的应用需要长时间运行,如 Blazor 服务器端应用,或者需要在一个请求/操作中多次创建和销毁 DbContext,以保持数据的一致性和避免资源泄漏,那么 LpEFContextFactoryRepositoryBase 将是更好的选择。
Product 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. 
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
1.3.5.9 183 2/12/2025
1.3.5.8 161 12/17/2024
1.3.5.7 163 12/17/2024
1.3.5.6 155 11/13/2024
1.3.5.5 178 9/25/2024
1.3.5.3 170 9/1/2024
1.3.5.2 149 8/29/2024
1.3.5.1 148 8/29/2024
1.3.4.4 203 8/19/2024
1.3.4.3 189 8/19/2024
1.3.4.2 176 8/19/2024
1.3.4.1 196 8/19/2024
1.3.4 172 8/1/2024
1.3.1 156 7/25/2024
1.3.0 174 7/25/2024
1.2.0 168 4/19/2024