Skip to content

mrploch/ploch-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

108 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build, Test and Analyze .NET pages-build-deployment Qodana

Quality Gate Status Coverage

Package Version Downloads
Ploch.Data.Model version downloads
Ploch.Data.GenericRepository version downloads
Ploch.Data.GenericRepository.EFCore version downloads
Ploch.Data.EFCore version downloads

Ploch.Data Libraries

A set of .NET libraries for building data access layers using standardised entity models, the Generic Repository and Unit of Work patterns, and Entity Framework Core.

Quick Start

// 1. Define entities using Ploch.Data.Model interfaces
public class Product : IHasId<int>, IHasTitle, IHasDescription, IHasAuditTimeProperties
{
    public int Id { get; set; }
    public string Title { get; set; } = null!;
    public string? Description { get; set; }
    public DateTimeOffset? CreatedTime { get; set; }
    public DateTimeOffset? ModifiedTime { get; set; }
    public DateTimeOffset? AccessedTime { get; set; }
}

// 2. Register in DI (reference Ploch.Data.GenericRepository.EFCore.SqLite
//    or Ploch.Data.GenericRepository.EFCore.SqlServer — same code for both)
using Ploch.Data.GenericRepository.EFCore.DependencyInjection;
builder.Services.AddDbContextWithRepositories<MyDbContext>();

// 3. Inject and use repositories
public class ProductService(IReadWriteRepositoryAsync<Product, int> repository)
{
    public Task<Product?> GetAsync(int id) => repository.GetByIdAsync(id);
    public Task<IList<Product>> SearchAsync(string term)
        => repository.GetAllAsync(p => p.Title.Contains(term));
}

Documentation

Full documentation is available in the docs/ folder:

Sample Application

A fully working Sample Application demonstrates entity modelling, repository operations, Unit of Work, pagination, eager loading, and integration testing.

Packages

Core

Package Description
Ploch.Data.Model Standardised entity interfaces (IHasId, INamed, IHasTitle, IHasAuditProperties, etc.) and common base types (Category, Tag, Property)

Entity Framework Core

Package Description
Ploch.Data.EFCore Design-time factory base classes, IDbContextConfigurator, data seeding, value converters
Ploch.Data.EFCore.SqLite SQLite provider: factory, configurator, DateTimeOffset workaround
Ploch.Data.EFCore.SqlServer SQL Server provider: factory, configurator

Generic Repository

Package Description
Ploch.Data.GenericRepository Provider-agnostic repository and Unit of Work interfaces
Ploch.Data.GenericRepository.EFCore EF Core implementations, DI registration via AddRepositories<TDbContext>()
Ploch.Data.GenericRepository.EFCore.SqLite One-call DI registration for SQLite (AddDbContextWithRepositories<TDbContext>())
Ploch.Data.GenericRepository.EFCore.SqlServer One-call DI registration for SQL Server (AddDbContextWithRepositories<TDbContext>())
Ploch.Data.GenericRepository.EFCore.Specification Ardalis.Specification integration

Testing

Package Description
Ploch.Data.EFCore.IntegrationTesting DataIntegrationTest<TDbContext> base class for EF Core tests
Ploch.Data.GenericRepository.EFCore.IntegrationTesting GenericRepositoryDataIntegrationTest<TDbContext> with repository/UoW helpers

Utilities

Package Description
Ploch.Data.Utilities Various utility types for working with data
Ploch.Data.StandardDataSets Common datasets (country lists, regions, etc.)

Features

A set of interfaces and base types for standardising entity models:

  • Core interfaces: IHasId<TId>, INamed, IHasTitle, IHasDescription, IHasContents, IHasNotes, IHasValue<TValue>
  • Audit interfaces: IHasAuditProperties, IHasAuditTimeProperties (and individual timestamp/user interfaces)
  • Hierarchical interfaces: IHierarchicalParentChildrenComposite<T> for tree structures
  • Categorisation: IHasCategories<TCategory>, IHasTags<TTag>
  • Common types: Category<T>, Tag, Property<TValue>, StringProperty, IntProperty, Image

A generic repository and unit of work pattern implementation for Entity Framework Core:

  • Layered repository interfaces: IQueryableRepository, IReadRepositoryAsync, IReadWriteRepositoryAsync
  • Unit of Work: IUnitOfWork with CommitAsync() and RollbackAsync()
  • One-line DI registration: services.AddDbContextWithRepositories<MyDbContext>() (provider-specific) or services.AddRepositories<MyDbContext>() (manual)
  • Zero-code database provider switching between SQLite and SQL Server
  • Pluggable IDbContextCreationLifecycle for provider-specific model configuration
  • Custom repository support with full interface registration
  • Specification pattern integration via Ardalis.Specification
  • Automatic audit property handling

Utility classes for EF Core including design-time DbContext factory base classes, runtime configurators for SQLite and SQL Server, and the SQLite DateTimeOffset workaround.

Base classes for integration tests using in-memory SQLite databases with automatic schema creation, repository helpers, and Unit of Work support.

Common data sets like country lists and regions.

Various utilities for working with data.

Packages

 
 
 

Contributors

Languages