TransactR.EntityFramework
0.2.0
See the version list below for details.
dotnet add package TransactR.EntityFramework --version 0.2.0
NuGet\Install-Package TransactR.EntityFramework -Version 0.2.0
<PackageReference Include="TransactR.EntityFramework" Version="0.2.0" />
<PackageVersion Include="TransactR.EntityFramework" Version="0.2.0" />
<PackageReference Include="TransactR.EntityFramework" />
paket add TransactR.EntityFramework --version 0.2.0
#r "nuget: TransactR.EntityFramework, 0.2.0"
#:package TransactR.EntityFramework@0.2.0
#addin nuget:?package=TransactR.EntityFramework&version=0.2.0
#tool nuget:?package=TransactR.EntityFramework&version=0.2.0
TransactR.EntityFramework
TransactR.EntityFramework
is a library that provides an IMementoStore
implementation based on Entity Framework Core, allowing you to persist transaction state directly in the application's database. This library integrates cleanly with an existing DbContext
, following an approach similar to OpenIddict.
Installation
First, install the NuGet package in your project.
dotnet add package TransactR.EntityFramework
Configuration
Configuration involves two simple steps:
1. Modifying the DbContext
To allow Entity Framework to create the necessary tables for mementos, you need to extend your DbContext
and add the entities. A clean way to do this is by using the UseTransactR
extension method in your DbContextOptionsBuilder
.
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options) { }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// Add your model configuration here...
}
}
Modify the DbContext
service configuration in your Program.cs
or Startup.cs
file to use the UseTransactR
extension method:
// Program.cs
builder.Services.AddDbContext<ApplicationDbContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"));
// Add the TransactR entities to your model.
options.UseTransactR<ApplicationDbContext, MyState, int>();
});
2. Adding Migrations
After configuring your DbContext
, run the following commands to create a migration that includes the TransactR tables:
dotnet ef migrations add AddTransactR
dotnet ef database update
This will create the Mementos
table in your database.
3. Service Injection
Finally, register the memento store in the Dependency Injection container:
// Program.cs
builder.Services.AddEntityFrameworkMementoStore<ApplicationDbContext, MyState, int>();
Usage Example
After configuration, you can inject IMementoStore<MyState, int>
into your services or controllers to save and retrieve mementos.
public class MyService
{
private readonly IMementoStore<MyState, int> _mementoStore;
public MyService(IMementoStore<MyState, int> mementoStore)
{
_mementoStore = mementoStore;
}
public async Task PerformOperationAsync(string transactionId, MyState state)
{
// Save a new memento
await _mementoStore.SaveAsync(transactionId, 1, state);
// Retrieve a memento
var retrievedMemento = await _mementoStore.RetrieveAsync(transactionId, 1);
// Remove a memento
await _mementoStore.RemoveAsync(transactionId, 1);
}
}
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 is compatible. 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
- Microsoft.EntityFrameworkCore (>= 8.0.0)
- Microsoft.EntityFrameworkCore.Abstractions (>= 8.0.0)
- System.ComponentModel.Annotations (>= 5.0.0)
- TransactR (>= 0.2.0)
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.0)
- Microsoft.EntityFrameworkCore.Abstractions (>= 9.0.0)
- System.ComponentModel.Annotations (>= 5.0.0)
- TransactR (>= 0.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.