![]() |
VOOZH | about |
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" />
<PackageVersion Include="Rebus.UnitOfWork" Version="7.0.1" />Directory.Packages.props
<PackageReference Include="Rebus.UnitOfWork" />Project file
paket add Rebus.UnitOfWork --version 7.0.1
#r "nuget: Rebus.UnitOfWork, 7.0.1"
#:package Rebus.UnitOfWork@7.0.1
#addin nuget:?package=Rebus.UnitOfWork&version=7.0.1Install as a Cake Addin
#tool nuget:?package=Rebus.UnitOfWork&version=7.0.1Install as a Cake Tool
Provides a unit of work helper for Rebus.
👁 alternate text is missing from this package README image
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 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
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. |
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 | 24,359 | 11/15/2023 |
| 7.0.0 | 2,245 | 11/15/2023 |
| 6.0.0 | 580,722 | 4/28/2020 |
| 4.0.0 | 144,743 | 8/15/2017 |
| 4.0.0-b02 | 1,221 | 5/18/2017 |
| 4.0.0-b01 | 1,166 | 5/1/2017 |
| 3.0.0 | 2,112 | 1/5/2017 |
| 2.0.0 | 1,954 | 9/20/2016 |
| 2.0.0-b01 | 1,207 | 9/9/2016 |
| 0.99.74 | 1,779 | 8/29/2016 |
| 0.99.73 | 1,521 | 8/12/2016 |
| 0.99.72 | 1,465 | 8/4/2016 |
| 0.99.71 | 1,784 | 8/3/2016 |
| 0.99.70 | 1,613 | 7/29/2016 |
| 0.99.68 | 1,498 | 7/18/2016 |
| 0.99.67 | 1,475 | 7/1/2016 |
| 0.99.66 | 1,509 | 6/28/2016 |
| 0.99.65 | 1,466 | 6/23/2016 |
| 0.99.64 | 1,450 | 6/22/2016 |
| 0.99.63 | 1,496 | 6/21/2016 |