Ozcorps.Generic
9.0.0
dotnet add package Ozcorps.Generic --version 9.0.0
NuGet\Install-Package Ozcorps.Generic -Version 9.0.0
<PackageReference Include="Ozcorps.Generic" Version="9.0.0" />
<PackageVersion Include="Ozcorps.Generic" Version="9.0.0" />
<PackageReference Include="Ozcorps.Generic" />
paket add Ozcorps.Generic --version 9.0.0
#r "nuget: Ozcorps.Generic, 9.0.0"
#:package Ozcorps.Generic@9.0.0
#addin nuget:?package=Ozcorps.Generic&version=9.0.0
#tool nuget:?package=Ozcorps.Generic&version=9.0.0
Ozcorps.Generic
Generic repository, unit-of-work, service, and CRUD controller base classes for ASP.NET Core with Entity Framework Core. Includes support for spatial queries, Snowflake IDs, soft-delete, audit fields, and optimistic concurrency versioning.
Installation
dotnet add package Ozcorps.Generic
<PackageReference Include="Ozcorps.Generic" Version="9.0.0" />
Core Concepts
| Building Block | Description |
|---|---|
EntityBase<TId> |
Abstract base class for all entities |
IRepository<T, TId> |
Generic data-access interface |
IUnitOfWork |
Coordinates repositories and saves changes |
EntityService<T, TId, TUserId> |
Business logic layer with CRUD, pagination, and spatial support |
CrudController<T, TId, TUserId> |
Ready-made HTTP endpoints wired to EntityService |
OzValueGenerator |
EF Core value generator backed by a DB sequence (PostgreSQL / MSSQL) |
SnowflakeValueGenerator |
EF Core value generator that produces distributed Snowflake IDs |
Entity Setup
1. Define your entity
using Ozcorps.Generic.Entity;
public class Product : EntityBase, IModifiedEntity
{
public string Name { get; set; } = string.Empty;
public decimal Price { get; set; }
// IModifiedEntity
public bool IsActive { get; set; }
public bool IsDeleted { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime? UpdatedAt { get; set; }
public long CreatedById { get; set; }
public long? UpdatedById { get; set; }
}
2. Entity interfaces
| Interface | Properties |
|---|---|
IModifiedEntity<TUserId> |
IsActive, IsDeleted, CreatedAt, UpdatedAt, CreatedById, UpdatedById |
IInsertedEntity<TUserId> |
CreatedAt, CreatedById |
IVersionedEntity |
Version (optimistic concurrency via long?) |
EntityService automatically populates audit fields and checks soft-delete when the entity implements these interfaces.
Repository & Unit of Work
// Resolve a typed repository
IRepository<Product> repo = unitOfWork.GetRepository<Product>();
// Common operations
Product? product = repo.Get(id);
IQueryable<Product> all = repo.GetQueryable();
repo.Add(product);
repo.Remove(id);
unitOfWork.Save();
EntityService
EntityService<T, TId, TUserId> provides full CRUD, pagination, and spatial intersection out of the box.
public class ProductService : EntityService<Product, long, long>, IProductService
{
public ProductService(IUnitOfWork unitOfWork) : base(unitOfWork) { }
}
Operations
| Method | Description |
|---|---|
Get(TId id) |
Fetch by ID (respects soft-delete if IModifiedEntity) |
Add(AddEntityDto dto, TUserId userId) |
Create from dynamic column map |
Update(UpdateEntityDto<TId> dto, TUserId userId) |
Patch from dynamic column map |
Remove(TId id, TUserId userId) |
Soft-delete or hard-delete |
Any(TId id) |
Check existence |
Intersect(string wkt) |
Spatial intersection query (WKT geometry) |
Paginate(PaginatorDto dto) |
Dynamic filtering, sorting, and paging |
CrudController
Inherit CrudController to get wired-up HTTP endpoints with zero boilerplate.
[ApiController]
[Route("api/[controller]")]
public class ProductController : CrudController<Product, long, long>
{
public ProductController(IEntityServiceProvider provider, ILogger<ProductController> logger)
: base(provider, logger) { }
protected override long GetCurrentUserId() =>
long.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)!);
}
Generated endpoints
| Verb | Route | Description |
|---|---|---|
GET |
/{id} |
Fetch single entity |
POST |
/ |
Create from AddEntityDto |
PUT |
/ |
Update from UpdateEntityDto |
DELETE |
/{id} |
Delete entity |
GET |
/paginate |
Paginated list |
GET |
/intersect |
Spatial intersection |
Value Generators
OzValueGenerator — Database sequences
// In OnModelCreating:
modelBuilder.Entity<Product>()
.Property(x => x.Id)
.HasValueGenerator((_, __) =>
new OzValueGenerator("product_id_seq", typeof(long), SequenceDbType.POSTGRE));
SnowflakeValueGenerator — Distributed IDs
modelBuilder.Entity<Order>()
.Property(x => x.Id)
.HasValueGenerator<SnowflakeValueGenerator>();
Snowflake IDs embed a timestamp, making them sortable and unique across nodes without a central counter.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net8.0
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.EntityFrameworkCore.Relational (>= 7.0.5)
- Ozcorps.Core (>= 9.1.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Ozcorps.Generic:
| Package | Downloads |
|---|---|
|
Ozcorps.Localization
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.