HoneyDrunk.Data.EntityFramework 0.3.0

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

HoneyDrunk.Data.EntityFramework

Entity Framework Core provider implementation for HoneyDrunk.Data. This package is provider-agnostic—database-specific configuration belongs in specialization packages (e.g., HoneyDrunk.Data.SqlServer).

Purpose

Implements the persistence abstractions using Entity Framework Core. Provides:

  • Base DbContext with tenant identity and correlation context access (not automatic filtering)
  • Repository implementation wrapping DbSet
  • EF-backed unit-of-work abstraction
  • Command interceptor for correlation tagging (relational providers, opt-in)
  • Health contributor for database connectivity

Allowed Dependencies

  • HoneyDrunk.Data.Abstractions - The contracts this package implements
  • HoneyDrunk.Data - The orchestration layer (required)
  • Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.Relational
  • Microsoft.Extensions.DependencyInjection.Abstractions
  • HoneyDrunk.Standards - Analyzer package only (PrivateAssets=all)

Note: Relational providers are required for diagnostics features (command interception). Non-relational EF Core providers may not support all features.

What Must Never Be Added

  • No database-specific packages - SQL Server, PostgreSQL, etc. belong in their respective projects
  • No transport or auth references - HoneyDrunk.Transport and HoneyDrunk.Auth are not data concerns

Namespace Layout

HoneyDrunk.Data.EntityFramework
├── Context/              # Base DbContext
│   └── HoneyDrunkDbContext.cs
├── Diagnostics/          # Interceptors and health
│   ├── CorrelationCommandInterceptor.cs
│   └── DbContextHealthContributor.cs
├── Modeling/             # Optional model conventions
│   └── ModelBuilderConventions.cs
├── Registration/         # DI extensions
│   ├── EfDataOptions.cs
│   └── ServiceCollectionExtensions.cs
├── Repositories/         # Repository implementation
│   └── EfRepository.cs
└── Transactions/         # UoW and transaction scope
    ├── EfTransactionScope.cs
    ├── EfUnitOfWork.cs
    └── EfUnitOfWorkFactory.cs

Usage

// Orchestration layer is required
services.AddHoneyDrunkData();

// Register EF Core provider (database configuration deferred to specialization package)
services.AddHoneyDrunkDataEntityFramework<MyDbContext>(
    options =>
    {
        // Database provider configured here or via specialization package
        // Example: options.UseSqlServer(...) requires HoneyDrunk.Data.SqlServer
    },
    efOptions =>
    {
        efOptions.EnableCorrelationInterceptor = true;  // Requires relational provider
        efOptions.RegisterHealthContributors = true;
    });

// Or use a specialization package (recommended):
// services.AddHoneyDrunkDataSqlServer<MyDbContext>(...);

Creating a DbContext

public class MyDbContext : HoneyDrunkDbContext
{
    public MyDbContext(
        DbContextOptions<MyDbContext> options,
        ITenantAccessor tenantAccessor,
        IDataDiagnosticsContext diagnosticsContext)
        : base(options, tenantAccessor, diagnosticsContext)
    {
    }

    public DbSet<MyEntity> MyEntities => Set<MyEntity>();

    protected override void ApplyConfigurations(ModelBuilder modelBuilder)
    {
        modelBuilder.ApplyConfigurationsFromAssembly(typeof(MyDbContext).Assembly);
        
        // Tenant filtering must be configured explicitly per entity
        // Example: modelBuilder.Entity<MyEntity>().HasQueryFilter(e => e.TenantId == CurrentTenantId.Value);
    }
}

Note: HoneyDrunkDbContext exposes CurrentTenantId and CorrelationId but does not automatically apply tenant filtering. Applications must configure query filters explicitly.

Using Repositories

public class MyService
{
    private readonly IUnitOfWork<MyDbContext> _unitOfWork;

    public MyService(IUnitOfWork<MyDbContext> unitOfWork)
    {
        _unitOfWork = unitOfWork;
    }

    public async Task CreateAsync(MyEntity entity, CancellationToken ct)
    {
        var repo = _unitOfWork.Repository<MyEntity>();
        await repo.AddAsync(entity, ct);
        await _unitOfWork.SaveChangesAsync(ct);  // Context-local save
    }
}

Note: EfRepository<T> implements IRepository<T> (which extends IReadOnlyRepository<T>). No separate read-only implementation exists—read-only access is a usage pattern, not a distinct type.

Lifetime and Threading

  • Scoped lifetime expected. This implementation assumes scoped DbContext lifetime (per-request in web applications).
  • Not thread-safe. DbContext and EfUnitOfWork are not thread-safe; do not share across threads.
  • Factory for controlled lifetime. Use EfUnitOfWorkFactory with IDbContextFactory<T> for background jobs or batch processing.

Correlation Tracking

Correlation tagging is opt-in and conditional:

  • Requires EnableCorrelationInterceptor = true
  • Requires relational EF Core provider
  • Requires diagnostics context to have a correlation ID

When all conditions are met, SQL commands include correlation comments:

/* correlation:01JXYZ... */
SELECT * FROM MyEntities WHERE Id = @p0
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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 HoneyDrunk.Data.EntityFramework:

Package Downloads
HoneyDrunk.Data.SqlServer

SQL Server specialization for HoneyDrunk.Data. Complete architecture overhaul with SQL Server and Azure SQL configuration, model conventions, retry-on-failure support, and enhanced health diagnostics.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.3.0 105 2/15/2026
0.2.0 118 1/6/2026

v0.3.0: Canary test coverage for Kernel context, outbox concurrency, and transport boundary invariants. No functional changes from v0.2.0.