ZEMA.Square.Lib
2.1.92
dotnet add package ZEMA.Square.Lib --version 2.1.92
NuGet\Install-Package ZEMA.Square.Lib -Version 2.1.92
<PackageReference Include="ZEMA.Square.Lib" Version="2.1.92" />
<PackageVersion Include="ZEMA.Square.Lib" Version="2.1.92" />
<PackageReference Include="ZEMA.Square.Lib" />
paket add ZEMA.Square.Lib --version 2.1.92
#r "nuget: ZEMA.Square.Lib, 2.1.92"
#:package ZEMA.Square.Lib@2.1.92
#addin nuget:?package=ZEMA.Square.Lib&version=2.1.92
#tool nuget:?package=ZEMA.Square.Lib&version=2.1.92
ZEMA Square
A comprehensive .NET 8 library for building enterprise web APIs with generic CRUD operations, role-based access control, JWT authentication, and identity management — out of the box.
Installation
dotnet add package ZEMA.Square.Lib
Quick Start
1. Register services in Program.cs
builder.Services.AddSquare(
configuration: builder.Configuration,
appAssemblies: new[] { typeof(Program).Assembly },
squareOptions: options =>
{
options.AppName = "MyApp";
options.TokenKey = "your-secret-key-min-32-chars";
options.TokenExpiresInMinutes = 60;
options.AllowRefreshToken = true;
},
squareDbContextOptionsAction: options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"))
);
app.UseSquareAuthentication();
2. Configure appsettings.json
{
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Database=mydb;Username=postgres;Password=password"
},
"Square": {
"AppName": "MyApplication",
"TokenKey": "your-secret-key-min-32-chars",
"TokenExpiresInMinutes": 60,
"AllowRefreshToken": true,
"Audience": "MyAppClient"
}
}
3. Define an entity
public class Product : Thing<int>
{
[Searchable]
public string Name { get; set; }
public decimal Price { get; set; }
}
4. Define a rule (business logic layer)
public class ProductRule : BaseRule<Product, ProductVm, ListProps, ProductVm, int>
{
public ProductRule(ISquareDBContext db, IMapper mapper) : base(db, mapper) { }
}
5. Define a controller
[Route("api/[controller]")]
public class ProductsController
: BaseValueController<ProductRule, Product, ProductVm, ListProps, ProductVm, int>
{
public ProductsController(ProductRule rule) : base(rule) { }
}
That's it — your endpoint now supports GET list, GET by id, POST, PUT, PATCH, and DELETE with pagination, filtering, sorting, and role-based authorization.
Features
| Feature | Description |
|---|---|
| Generic CRUD | List, get, create, update, patch (JSON Patch), delete |
| RBAC | Users, roles, and screen-level permissions |
| JWT Auth | Token generation, refresh tokens, configurable expiry |
| Identity | Registration, login, password/email/phone flows |
| Multi-Language | messages.json-driven translations; auto-detected from Accept-Language header |
| Data Sync | Master-detail synchronization with secret validation |
| Soft Delete | ArchivableThing<TKey> base entity |
| Owner Scoping | OwnerBaseThing<TKey> for owner-filtered data |
| Dynamic Filtering | Search, sort, and page any entity |
| Validation | FluentValidation integration with localized error messages |
| AutoMapper | Built-in entity-to-DTO mapping profiles |
| Swagger | OpenAPI documentation support |
Base Entity Types
| Class | Use when... |
|---|---|
Thing<TKey> |
Standard entity — adds Id, CreatedDate, UpdatedDate |
ArchivableThing<TKey> |
Need soft-delete (IsArchived flag) |
OwnerBaseThing<TKey> |
Data is scoped to a specific owner |
PersonalThing<TKey, TPersonalId> |
User-personal records |
Primary Key Variants
| Controller Base | Rule Base | Key Type |
|---|---|---|
BaseValueController<> |
BaseRule<> |
int / numeric |
BaseGuidController<> |
BaseGuidRule<> |
Guid |
BaseStringController<> |
BaseStringRule<> |
string |
Built-in Endpoints
ZEMA Square registers the following ready-to-use controllers automatically:
POST /api/account/login— authenticate and receive a JWTPOST /api/account/refresh— refresh an expired tokenGET/POST/PUT/DELETE /api/users— user managementGET/POST/PUT/DELETE /api/roles— role managementGET/POST/PUT/DELETE /api/screens— screen / permission management
Multi-Language Support
All built-in error and validation messages are driven by a messages.json file. The library ships with English (en), Armenian (hy), and Russian (ru) translations out of the box.
The active language is resolved automatically from the request's Accept-Language header, with English as the fallback. You can override any message or add new languages by placing your own messages.json in the application directory, or by pointing MessagesDirectory in SquareOptions to a custom path.
// Read a message in code — language auto-detected from the HTTP request
string msg = Messages.Get(nameof(Messages.WrongCredentials));
// Or request a specific language explicitly
string msg = Messages.Get(nameof(Messages.WrongCredentials), "hy");
{
"en": { "WrongCredentials": "Wrong username or password." },
"hy": { "WrongCredentials": "Սխալ օգտանուն կամ գաղտնաբառ։" },
"ru": { "WrongCredentials": "Неверное имя пользователя или пароль." }
}
Requirements
- .NET 8.0+
- PostgreSQL (via Npgsql EF Core provider)
- ASP.NET Core 8
License
Copyright © ZEMA Enterprises. All rights reserved.
| 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
- AutoMapper (>= 16.1.1)
- FluentValidation.AspNetCore (>= 11.3.1)
- Google.Apis.Auth (>= 1.73.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.24)
- Microsoft.AspNetCore.Identity (>= 2.3.9)
- Microsoft.AspNetCore.Identity.EntityFrameworkCore (>= 8.0.3)
- Microsoft.AspNetCore.JsonPatch (>= 9.0.8)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.AspNetCore.Mvc.NewtonsoftJson (>= 8.0.4)
- Microsoft.EntityFrameworkCore (>= 8.0.6)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
- Microsoft.IdentityModel.Tokens (>= 8.16.0)
- Newtonsoft.Json (>= 13.0.4)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 8.0.2)
- Swashbuckle.AspNetCore.SwaggerGen (>= 6.5.0)
- System.IdentityModel.Tokens.Jwt (>= 8.16.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ZEMA.Square.Lib:
| Package | Downloads |
|---|---|
|
ZEMA.SquareOrganization
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.92 | 107 | 5/29/2026 |
| 2.1.91 | 119 | 5/27/2026 |
| 2.1.90 | 108 | 5/25/2026 |
| 2.1.89 | 128 | 5/20/2026 |
| 2.1.88 | 165 | 5/18/2026 |
| 2.0.9 | 125 | 4/22/2026 |
| 2.0.8 | 116 | 4/21/2026 |
| 2.0.7 | 137 | 4/17/2026 |
| 1.2.12 | 148 | 2/5/2026 |
| 1.2.11 | 149 | 2/2/2026 |
| 1.2.10 | 129 | 1/30/2026 |
| 1.2.9 | 126 | 1/29/2026 |
| 1.2.8 | 127 | 1/26/2026 |
| 1.2.7 | 230 | 1/22/2026 |
| 1.2.6 | 805 | 1/12/2026 |
| 1.2.5 | 150 | 12/29/2025 |
| 1.2.4 | 144 | 12/26/2025 |
| 1.2.3 | 189 | 12/26/2025 |
| 1.2.2 | 166 | 12/26/2025 |
| 1.1.87 | 157 | 12/12/2025 |