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
                    
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="ZEMA.Square.Lib" Version="2.1.92" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZEMA.Square.Lib" Version="2.1.92" />
                    
Directory.Packages.props
<PackageReference Include="ZEMA.Square.Lib" />
                    
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 ZEMA.Square.Lib --version 2.1.92
                    
#r "nuget: ZEMA.Square.Lib, 2.1.92"
                    
#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 ZEMA.Square.Lib@2.1.92
                    
#: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=ZEMA.Square.Lib&version=2.1.92
                    
Install as a Cake Addin
#tool nuget:?package=ZEMA.Square.Lib&version=2.1.92
                    
Install as a Cake Tool

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 JWT
  • POST /api/account/refresh — refresh an expired token
  • GET/POST/PUT/DELETE /api/users — user management
  • GET/POST/PUT/DELETE /api/roles — role management
  • GET/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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed