Shuttle.Extensions.EFCore 20.0.2

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

Shuttle.Extensions.EFCore

PM> Shuttle.Extensions.EFCore

Extensions for Entity Framework Core.

Configuration

services.AddSingleton<IDbContextService, DbContextService>();

Usage

The DbContextService is a simple service that provides a DbContext instance. This is useful when you need to create a DbContext instance in a service that is not registered with the service collection and you need to use the same DbContext in multiple dependencies without having to use the DbContextFactory in each.

private readonly IDbContextFactory<RequiredDbContext> _dbContextFactory;
private readonly IDbContextService _dbContextService;
private readonly IDependencyA _dependencyA;
private readonly IDependencyB _dependencyB;

public Processor(IDbContextService dbContextService, IDbContextFactory<RequiredDbContext> dbContextFactory, IDependencyA dependencyA, IDependencyB dependencyB)
{
    _dbContextService = Guard.AgainstNull(dbContextService);
    _dbContextFactory = Guard.AgainstNull(dbContextFactory);
    _dependencyA = Guard.AgainstNull(dependencyA);
    _dependencyB = Guard.AgainstNull(dependencyB);
}

public async Task ExecuteAsync(CancellationToken cancellationToken = default)
{
    using (var tx = new TransactionScope(TransactionScopeOption.Required, TransactionScopeAsyncFlowOption.Enabled))
    await using (var dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken))
    using (_dbContextService.Add(dbContext))
    {
        _dependencyA.Process();
        _dependencyB.Process();

        tx.Complete();
    }
}

The dependencies IDependencyA and IDependencyB can now use the DbContext instance that was created in the Processor class:

public class DependencyA : IDependencyA
{
    private readonly IDbContextService _dbContextService;
    p
    ublic DependencyA(IDbContextService dbContextService)
    {
        _dbContextService = Guard.AgainstNull(dbContextService);
    }
    
    public void Process()
    {
        var dbContext = _dbContextService.Get<RequiredDbContext>();
        // use the dbContext instance
    }
}

There is also a DbContextScope that can be used to create a new scope within an asynchronous flow. Please see the ScopeFixture for more information.

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 Shuttle.Extensions.EFCore:

Package Downloads
Shuttle.Extensions.EFCore.ThreadDbContextScope

Create a new DbContextScope per processor thread.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
20.0.2 503 7/13/2025
20.0.1 385 3/18/2025
20.0.0 222 2/2/2025