BytLabs.Domain 5.2.0-alpha.125

This is a prerelease version of BytLabs.Domain.
dotnet add package BytLabs.Domain --version 5.2.0-alpha.125
                    
NuGet\Install-Package BytLabs.Domain -Version 5.2.0-alpha.125
                    
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="BytLabs.Domain" Version="5.2.0-alpha.125" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BytLabs.Domain" Version="5.2.0-alpha.125" />
                    
Directory.Packages.props
<PackageReference Include="BytLabs.Domain" />
                    
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 BytLabs.Domain --version 5.2.0-alpha.125
                    
#r "nuget: BytLabs.Domain, 5.2.0-alpha.125"
                    
#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 BytLabs.Domain@5.2.0-alpha.125
                    
#: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=BytLabs.Domain&version=5.2.0-alpha.125&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=BytLabs.Domain&version=5.2.0-alpha.125&prerelease
                    
Install as a Cake Tool

BytLabs Backend Packages

A batteries-included foundation for building consistent .NET microservices.

BytLabs Backend Packages is a curated set of .NET libraries that encode one opinionated, production-ready way to build a service โ€” Domain-Driven Design, CQRS, MongoDB persistence, multitenancy, GraphQL, and observability โ€” so every microservice across an organization looks and behaves the same. Wire up a new service in minutes and spend your time on business logic, not plumbing.

.NET GraphQL MongoDB License: MIT


Why BytLabs?

Without a shared foundation With BytLabs
Every team wires DDD/CQRS/persistence differently One consistent architecture across all services
Boilerplate for logging, tracing, health, tenancy Configured in a few fluent calls
Inconsistent error handling and API contracts Standardized GraphQL errors and mutation conventions
Hand-rolled MongoDB access and tenant isolation Generic repository + automatic database-per-tenant
Slow, divergent service bootstrap Start from a working template in minutes

The result: uniform architecture, consistent error handling & logging, standardized testing, shared domain patterns, and common security practices โ€” onboarding and maintenance get dramatically cheaper.


What you get

  • ๐ŸŽฏ Domain-Driven Design โ€” aggregates, entities, value objects, domain events, soft-delete, audit, business rules.
  • โšก CQRS โ€” commands/queries on MediatR with automatic FluentValidation and logging pipelines.
  • ๐Ÿ—„๏ธ MongoDB data access โ€” generic repository, unit-of-work, transactions, and a dynamic-data query engine.
  • ๐Ÿข Multitenancy โ€” request-scoped tenant resolution with transparent database-per-tenant isolation.
  • ๐Ÿš€ GraphQL API โ€” HotChocolate with BytLabs defaults: mutation conventions, typed errors, authorization, projections/filtering/sorting.
  • ๐Ÿ“Š Observability โ€” Serilog + OpenTelemetry (logs, metrics, traces) and liveness/readiness/startup health checks.
  • ๐Ÿงฉ Dynamic data โ€” schema-less JSON fields on aggregates, queryable and filterable through the API.
  • ๐Ÿ” State machines (optional) โ€” rule-guarded state transitions for aggregates with a formal lifecycle.

Architecture at a glance

Services built on these packages follow Clean Architecture / DDD with four layers, each mapped to a package:

---
config:
  look: handDrawn
  theme: neutral
---
flowchart TB
    API["API โ€” BytLabs.Api, BytLabs.Api.Graphql<br/>GraphQL endpoints, host, typed errors"]
    APP["Application โ€” BytLabs.Application<br/>commands, queries, handlers, validation"]
    DOM["Domain โ€” BytLabs.Domain (+ BytLabs.States.Domain)<br/>aggregates, value objects, events, rules"]
    INF["Infrastructure โ€” BytLabs.DataAccess, BytLabs.DataAccess.MongoDB<br/>MongoDB persistence and DI wiring"]
    CC["Cross-cutting โ€” BytLabs.Multitenancy, BytLabs.Observability"]

    API --> APP
    APP --> DOM
    INF --> APP
    INF --> DOM
    CC -.-> API
    CC -.-> INF

Package catalog

Full, example-driven docs for each package live in the Library Reference.

Core

Package Description Docs
BytLabs.Domain DDD building blocks: Entity, AggregateRootBase, ValueObject, domain events, audit, soft-delete, dynamic data, business rules โ†’
BytLabs.Application CQRS (ICommand/IQuery + handlers), IRepository/IUnitOfWork, DomainEventHandler, validation + logging pipeline, AddCQS โ†’

Data access

Package Description Docs
BytLabs.DataAccess Provider-agnostic unit-of-work, command transactions, domain-event dispatch โ†’
BytLabs.DataAccess.MongoDB MongoDB repository, per-tenant database, BSON setup, dynamic-data queries, health checks โ†’

API / hosting

Package Description Docs
BytLabs.Api ApiServiceBuilder fluent host (context, tenancy, logging, metrics, tracing, health), config binding โ†’
BytLabs.Api.Graphql HotChocolate setup with BytLabs defaults, typed errors, type registration, dynamic-data inputs โ†’

Cross-cutting & optional

Package Description Docs
BytLabs.Multitenancy Tenant resolution + database-per-tenant โ†’
BytLabs.Observability Serilog + OpenTelemetry + health checks โ†’
BytLabs.States.Domain State-machine aggregates (RulesEngine) โ†’
BytLabs.Infrastructure Shared infrastructure exception (placeholder) โ†’

Getting started

The fastest path is the BytLabs.MicroserviceTemplate, a working service that doubles as a recipe catalog: a minimal Order aggregate plus an advanced Product aggregate demonstrating every pattern (dynamic data, soft-delete, sub-entities, advanced GraphQL, authorization), each with a focused how-to doc. Copy it, rename, and build your domain.

Option B โ€” Add the packages to an existing service

Requirements: .NET 8 SDK, MongoDB โ‰ฅ 4.2 (the MongoDB driver is 3.x), and an OpenTelemetry collector if you want to export telemetry.

Packages are versioned together. With central package management (Directory.Packages.props):

<PropertyGroup>
  <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  <BytLabsPackageVersion>4.2.0</BytLabsPackageVersion>
</PropertyGroup>
<ItemGroup>
  <PackageVersion Include="BytLabs.Domain"             Version="$(BytLabsPackageVersion)" />
  <PackageVersion Include="BytLabs.Application"        Version="$(BytLabsPackageVersion)" />
  <PackageVersion Include="BytLabs.DataAccess"         Version="$(BytLabsPackageVersion)" />
  <PackageVersion Include="BytLabs.DataAccess.MongoDB" Version="$(BytLabsPackageVersion)" />
  <PackageVersion Include="BytLabs.Api"               Version="$(BytLabsPackageVersion)" />
  <PackageVersion Include="BytLabs.Api.Graphql"       Version="$(BytLabsPackageVersion)" />
</ItemGroup>

Quick tour

1. Host (Program.cs) โ€” one fluent chain wires the standard concerns:

var builder = WebApplication.CreateBuilder(args);

var app = ApiServiceBuilder.CreateBuilder(builder)
    .WithHttpContextAccessor(uc => uc.AddResolver<HttpUserContextResolver>())
    .WithMultiTenantContext(mt => mt.AddResolver<FromHeaderTenantIdResolver>())
    .WithLogging().WithMetrics().WithTracing().WithHealthChecks()
    .WithServiceConfiguration(services =>
    {
        services.AddInfrastructure(builder.Configuration);   // your DI (below)
        services.AddGraphQLService()
            .AddMongoDbQuerySettings()
            .AddCommandTypes().AddDtoTypes()
            .AddMutationType<Mutation>().AddQueryType<Query>();
    })
    .BuildWebApp(app => { app.UseAuthentication(); app.UseAuthorization(); app.MapGraphQL(); });

app.Run();

2. Infrastructure wiring โ€” CQS + AutoMapper + per-aggregate repositories:

services.AddCQS(new[] { typeof(CreateProductCommand).Assembly });
services.AddAutoMapper(typeof(ProductMappingProfile));
services.AddMongoDatabase(config.GetConfiguration<MongoDatabaseConfiguration>())
    .AddMongoRepository<Product, Guid>();

3. A feature โ€” aggregate โ†’ command โ†’ handler:

public sealed class Product : AggregateRootBase<Guid>, ISoftDeletable
{
    public string Name { get; private set; }
    public bool IsDeleted { get; private set; }
    private Product(Guid id, string name) : base(id) => Name = name;
    public static Product Create(Guid id, string name)
    {
        var p = new Product(id, name);
        p.AddDomainEvent(new ProductCreated(id, name));
        return p;
    }
}

public record CreateProductCommand(Guid Id, string Name) : ICommand<ProductDto>;

public class CreateProductCommandHandler(IRepository<Product, Guid> repo, IMapper mapper)
    : ICommandHandler<CreateProductCommand, ProductDto>
{
    public async Task<ProductDto> Handle(CreateProductCommand request, CancellationToken ct)
        => mapper.Map<ProductDto>(await repo.InsertAsync(Product.Create(request.Id, request.Name), ct));
}

That's a complete, multi-tenant, observable, validated GraphQL mutation. See the Library Reference for the full API of each building block.

Configuration

{
  "ObservabilityConfiguration": {
    "ServiceName": "my-service",
    "CollectorUrl": "http://localhost:4317",
    "Timeout": 1000
  },
  "MongoDatabaseConfiguration": {
    "DatabaseName": "myService",
    "ConnectionString": "mongodb://localhost:27017?retryWrites=false",
    "UseTransactions": false
  }
}

Multitenancy: each tenant's data lives in its own database, "{DatabaseName}-{tenantId}", resolved per request (e.g. a Tenant header). Your domain code needs no tenant field or filter. Transactions: MongoDB transactions require a replica set โ€” keep UseTransactions: false for a standalone server.


Documentation

  • ๐Ÿ“– Library Reference โ€” per-package guides with usage examples (this repo).
  • ๐Ÿš€ Getting Started
  • ๐ŸŒ Published docs: docs.bytlabs.co
  • ๐Ÿงช Recipe catalog โ€” end-to-end patterns in the BytLabs.MicroserviceTemplate (docs/recipes/).

Docs are built with DocFX. Build locally:

docfx docfx.json --serve

Versioning & compatibility

  • All BytLabs packages share a single version (BytLabsPackageVersion) โ€” upgrade them together.
  • Targets .NET 8. Requires MongoDB โ‰ฅ 4.2 (MongoDB.Driver 3.x), HotChocolate 14.

Support

Contributing

Contributions are welcome. Fork, create a feature branch, and open a pull request. Please keep changes consistent with the existing architecture and add/update the relevant page under docs/libraries/.

License

Licensed under the MIT License โ€” see LICENSE.

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 (3)

Showing the top 3 NuGet packages that depend on BytLabs.Domain:

Package Downloads
BytLabs.Application

Package Description

BytLabs.States.Domain

Package Description

BytLabs.Forms.Domain

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.2.0-alpha.125 76 7/21/2026
5.2.0-alpha.124 72 7/20/2026
5.2.0-alpha.123 82 7/19/2026
5.1.0-alpha.122 80 7/18/2026
5.1.0-alpha.121 80 7/18/2026
5.1.0-alpha.120 71 7/18/2026
5.1.0-alpha.119 72 7/18/2026
4.2.0-alpha.118 74 7/16/2026
4.2.0-alpha.116 65 7/16/2026
4.2.0-alpha.115 78 7/16/2026
4.2.0-alpha.114 76 7/15/2026
4.2.0-alpha.113 88 7/13/2026
4.2.0-alpha.112 73 7/12/2026
4.2.0-alpha.107 182 5/3/2025
4.2.0-alpha.106 111 5/3/2025
4.2.0-alpha.105 274 4/29/2025
4.2.0-alpha.104 189 4/29/2025
4.2.0-alpha.103 198 4/29/2025
4.2.0-alpha.102 200 4/28/2025
4.1.0-alpha.108 182 7/7/2025
Loading failed