Rebus.UnitOfWork
7.0.1
dotnet add package Rebus.UnitOfWork --version 7.0.1
NuGet\Install-Package Rebus.UnitOfWork -Version 7.0.1
<PackageReference Include="Rebus.UnitOfWork" Version="7.0.1" />
paket add Rebus.UnitOfWork --version 7.0.1
#r "nuget: Rebus.UnitOfWork, 7.0.1"
// Install Rebus.UnitOfWork as a Cake Addin #addin nuget:?package=Rebus.UnitOfWork&version=7.0.1 // Install Rebus.UnitOfWork as a Cake Tool #tool nuget:?package=Rebus.UnitOfWork&version=7.0.1
Rebus.UnitOfWork
Provides a unit of work helper for Rebus.
The unit of work helper works with C# generics and lets you represent your unit of work as anything that makes sense to you.
You configure it like this:
Configure.With(activator)
.Transport(t => t.Use(...))
.Options(o => o.EnableUnitOfWork(...))
.Start();
for the synchronous version, or
Configure.With(activator)
.Transport(t => t.Use(...))
.Options(o => o.EnableAsyncUnitOfWork(...))
.Start();
if you want a unit of work that supports asynchronous creation, completion, etc.
An example could be an Entity Framework database context, MyDbContext
, which you then manage like this:
Configure.With(activator)
.Transport(t => t.Use(...))
.Options(o => o.EnableAsyncUnitOfWork(
create: async context => new MyDbContext(),
commit: async (context, uow) => await uow.SaveChangesAsync(),
dispose: async (context, uow) => uow.Dispose()
))
.Start();
By the power of C# generics, uow
passed to the commit
and dispose
functions above will have the save type as
the one returned from the create
method.
context
will be the current IMessageContext
, which is also statically accessible via MessageContext.Current
,
this way enabling injection of your unit of work by using the message context to share it:
Configure.With(activator)
.Transport(t => t.Use(...))
.Options(o => o.EnableAsyncUnitOfWork(
create: async context =>
{
var uow = new MyDbContext();
context.TransactionContext.Items["current-uow"] = uow;
return uow;
},
commit: async (context, uow) => await uow.SaveChangesAsync(),
dispose: async (context, uow) => uow.Dispose()
))
.Start();
and then you can configure your IoC container to be able to inject MyDbContext
- e.g. with Microsoft Extensions Dependency Injection like this:
services.AddScoped(p =>
{
var context = p.GetService<IMessageContext>()
?? throw new InvalidOperationException("Cannot resolve db context outside of Rebus handler, sorry");
return context.TransactionContext.Items.TryGetValue("current-uow", out var result)
? (MyDbContext)result
: throw new ArgumentException("Didn't find db context under 'current-uow' key in current context");
});
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Rebus (>= 8.0.1)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Rebus.UnitOfWork:
Package | Downloads |
---|---|
Revo.Rebus
Event Sourcing, CQRS and DDD framework for modern C#/.NET applications. Rebus (service bus) messaging integration package. |
|
Vedaantees.Framework.Providers
Providers implementation for the framework. |
|
Dbosoft.Rebus.SimpleInjector
A extension to Rebus to configure transports and other settings via dependency injection. |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Rebus.UnitOfWork:
Repository | Stars |
---|---|
revoframework/Revo
Event Sourcing, CQRS and DDD framework for C#/.NET Core.
|
|
rebus-org/RebusSamples
Small sample projects
|
Version | Downloads | Last updated |
---|---|---|
7.0.1 | 2,641 | 11/15/2023 |
7.0.0 | 246 | 11/15/2023 |
6.0.0 | 547,865 | 4/28/2020 |
4.0.0 | 143,670 | 8/15/2017 |
4.0.0-b02 | 826 | 5/18/2017 |
4.0.0-b01 | 772 | 5/1/2017 |
3.0.0 | 1,591 | 1/5/2017 |
2.0.0 | 1,455 | 9/20/2016 |
2.0.0-b01 | 792 | 9/9/2016 |
0.99.74 | 1,244 | 8/29/2016 |
0.99.73 | 1,006 | 8/12/2016 |
0.99.72 | 963 | 8/4/2016 |
0.99.71 | 1,270 | 8/3/2016 |
0.99.70 | 1,095 | 7/29/2016 |
0.99.68 | 986 | 7/18/2016 |
0.99.67 | 959 | 7/1/2016 |
0.99.66 | 990 | 6/28/2016 |
0.99.65 | 958 | 6/23/2016 |
0.99.64 | 947 | 6/22/2016 |
0.99.63 | 982 | 6/21/2016 |
0.99.62 | 1,008 | 6/17/2016 |
0.99.61 | 945 | 6/17/2016 |
0.99.60 | 1,096 | 6/15/2016 |
0.99.59 | 1,018 | 6/3/2016 |
0.99.58 | 1,030 | 5/24/2016 |
0.99.57 | 1,015 | 5/22/2016 |
0.99.56 | 1,024 | 5/22/2016 |
0.99.55 | 1,016 | 5/16/2016 |
0.99.54 | 984 | 5/12/2016 |
0.99.53 | 962 | 5/12/2016 |
0.99.52 | 969 | 5/11/2016 |
0.99.51 | 965 | 5/9/2016 |
0.99.50 | 997 | 4/13/2016 |
0.99.48 | 1,019 | 4/6/2016 |
0.99.47 | 995 | 3/31/2016 |
0.99.46 | 991 | 3/30/2016 |
0.99.45 | 987 | 3/29/2016 |
0.99.44 | 982 | 3/26/2016 |
0.99.43 | 1,001 | 3/26/2016 |
0.99.42 | 992 | 3/22/2016 |
0.99.41 | 953 | 3/17/2016 |
0.99.40 | 1,031 | 3/15/2016 |
0.99.39 | 976 | 3/14/2016 |
0.99.38 | 972 | 3/9/2016 |
0.99.37 | 1,002 | 3/9/2016 |
0.99.36 | 959 | 3/3/2016 |
0.99.35 | 1,013 | 2/22/2016 |
0.99.34 | 987 | 2/19/2016 |
0.99.33 | 1,102 | 2/12/2016 |
0.99.32 | 995 | 2/10/2016 |
0.99.31 | 1,014 | 2/8/2016 |
0.99.30 | 996 | 2/5/2016 |
0.99.29 | 987 | 2/2/2016 |
0.99.27 | 1,044 | 1/28/2016 |
0.99.26 | 966 | 1/27/2016 |
0.99.25 | 1,015 | 1/22/2016 |