BytLabs.DataAccess.EntityFramework
4.2.0-alpha.112
dotnet add package BytLabs.DataAccess.EntityFramework --version 4.2.0-alpha.112
NuGet\Install-Package BytLabs.DataAccess.EntityFramework -Version 4.2.0-alpha.112
<PackageReference Include="BytLabs.DataAccess.EntityFramework" Version="4.2.0-alpha.112" />
<PackageVersion Include="BytLabs.DataAccess.EntityFramework" Version="4.2.0-alpha.112" />
<PackageReference Include="BytLabs.DataAccess.EntityFramework" />
paket add BytLabs.DataAccess.EntityFramework --version 4.2.0-alpha.112
#r "nuget: BytLabs.DataAccess.EntityFramework, 4.2.0-alpha.112"
#:package BytLabs.DataAccess.EntityFramework@4.2.0-alpha.112
#addin nuget:?package=BytLabs.DataAccess.EntityFramework&version=4.2.0-alpha.112&prerelease
#tool nuget:?package=BytLabs.DataAccess.EntityFramework&version=4.2.0-alpha.112&prerelease
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.
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
Option A โ Start from the template (recommended)
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. aTenantheader). Your domain code needs no tenant field or filter. Transactions: MongoDB transactions require a replica set โ keepUseTransactions: falsefor 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
- ๐ฌ Discussions
- ๐ Issue Tracker
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 | 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
- BytLabs.DataAccess (>= 4.2.0-alpha.112)
- BytLabs.Multitenancy (>= 4.2.0-alpha.112)
- GuardClauses (>= 1.2.4)
- Microsoft.EntityFrameworkCore (>= 8.0.10)
- Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore (>= 8.0.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.2.0-alpha.112 | 0 | 7/12/2026 |