Gtlabs.Persistence
1.4.1
dotnet add package Gtlabs.Persistence --version 1.4.1
NuGet\Install-Package Gtlabs.Persistence -Version 1.4.1
<PackageReference Include="Gtlabs.Persistence" Version="1.4.1" />
<PackageVersion Include="Gtlabs.Persistence" Version="1.4.1" />
<PackageReference Include="Gtlabs.Persistence" />
paket add Gtlabs.Persistence --version 1.4.1
#r "nuget: Gtlabs.Persistence, 1.4.1"
#:package Gtlabs.Persistence@1.4.1
#addin nuget:?package=Gtlabs.Persistence&version=1.4.1
#tool nuget:?package=Gtlabs.Persistence&version=1.4.1
Gtlabs.Persistence
Persistence library for .NET applications that provides integrations and conventions on top of Entity Framework Core using Repository and Unit of Work patterns. Includes base entities (auditing, soft-delete), a custom DbContext, migration extensions and a service to apply migrations at startup.
Structure (summary)
- CustomDbContext/: custom
DbContextimplementation used by the application. - Entities/: base entities (
Entity,AuditedEntity,SoftDeleteEntity). - Extensions/: helpers for database configuration and migrations.
- Repository/:
IRepository,RepositoryandUnitOfWork. - Services/: service to apply migrations automatically.
Use case: CustomDbContext
Use GtLabsDbContext to centralize model configuration, conventions and auditing/interceptors before using repositories or EF directly.
Example:
// register in DI
services.AddDbContext<GtLabsDbContext>(opts =>
opts.UseSqlServer(configuration.GetConnectionString("Default")));
// inject and use
public class MyAppService
{
private readonly GtLabsDbContext _db;
public MyAppService(GtLabsDbContext db) => _db = db;
public void Add<T>(T entity) where T : class
{
_db.Set<T>().Add(entity);
_db.SaveChanges();
}
}
Use case: Repository
Use the Repository pattern to isolate data access logic from the application layer, simplifying tests and centralizing query rules.
Example:
public class MyService
{
private readonly IRepository<MyEntity> _repo;
private readonly IUnitOfWork _uow;
public MyService(IRepository<MyEntity> repo, IUnitOfWork uow)
{
_repo = repo;
_uow = uow;
}
public IEnumerable<MyEntity> ListActive()
{
return _repo.Where(e => !e.IsDeleted).ToList();
}
public void Create(MyEntity e)
{
_repo.Add(e);
_uow.SaveChanges();
}
}
Installation
Add the project reference or publish as a NuGet package and reference it in your project.
License
See the LICENSE file in the root repository for details.
| 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
- Gtlabs.AmbientData (>= 1.4.1)
- Gtlabs.Core (>= 1.4.1)
- Gtlabs.DependencyInjections (>= 1.4.1)
- Microsoft.EntityFrameworkCore (>= 9.0.10)
- Microsoft.EntityFrameworkCore.Abstractions (>= 9.0.10)
- Microsoft.EntityFrameworkCore.Relational (>= 9.0.10)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.10)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 9.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.