{"id":19383241,"url":"https://github.com/rebus-org/rebus.unitofwork","last_synced_at":"2026-01-21T09:33:38.405Z","repository":{"id":37925174,"uuid":"67026474","full_name":"rebus-org/Rebus.UnitOfWork","owner":"rebus-org","description":":bus: Unit of work helper for Rebus","archived":false,"fork":false,"pushed_at":"2024-08-09T22:00:54.000Z","size":3071,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-23T21:38:00.702Z","etag":null,"topics":["rebus","unitofwork"],"latest_commit_sha":null,"homepage":"https://mookid.dk/category/rebus","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rebus-org.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-31T10:07:01.000Z","updated_at":"2024-08-09T22:00:58.000Z","dependencies_parsed_at":"2024-07-10T12:19:16.205Z","dependency_job_id":"a59bb5a6-99dd-44c6-a3ab-e705355b39df","html_url":"https://github.com/rebus-org/Rebus.UnitOfWork","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/rebus-org/Rebus.UnitOfWork","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebus-org%2FRebus.UnitOfWork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebus-org%2FRebus.UnitOfWork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebus-org%2FRebus.UnitOfWork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebus-org%2FRebus.UnitOfWork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rebus-org","download_url":"https://codeload.github.com/rebus-org/Rebus.UnitOfWork/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rebus-org%2FRebus.UnitOfWork/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28631172,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T04:47:28.174Z","status":"ssl_error","status_checked_at":"2026-01-21T04:47:22.943Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rebus","unitofwork"],"created_at":"2024-11-10T09:25:10.096Z","updated_at":"2026-01-21T09:33:38.387Z","avatar_url":"https://github.com/rebus-org.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rebus.UnitOfWork\n\n[![install from nuget](https://img.shields.io/nuget/v/Rebus.UnitOfWork.svg?style=flat-square)](https://www.nuget.org/packages/Rebus.UnitOfWork)\n\nProvides a unit of work helper for [Rebus](https://github.com/rebus-org/Rebus).\n\n![](https://raw.githubusercontent.com/rebus-org/Rebus/master/artwork/little_rebusbus2_copy-200x200.png)\n\n---\n\nThe unit of work helper works with C# generics and lets you represent your unit of work as anything that makes sense to you.\n\nYou configure it like this:\n\n```csharp\nConfigure.With(activator)\n    .Transport(t =\u003e t.Use(...))\n    .Options(o =\u003e o.EnableUnitOfWork(...))\n    .Start();\n```\n\nfor the synchronous version, or\n\n```csharp\nConfigure.With(activator)\n    .Transport(t =\u003e t.Use(...))\n    .Options(o =\u003e o.EnableAsyncUnitOfWork(...))\n    .Start();\n```\n\nif you want a unit of work that supports asynchronous creation, completion, etc.\n\nAn example could be an Entity Framework database context, `MyDbContext`, which you then manage like this:\n\n```csharp\nConfigure.With(activator)\n    .Transport(t =\u003e t.Use(...))\n    .Options(o =\u003e o.EnableAsyncUnitOfWork(\n        create: async context =\u003e new MyDbContext(),\n        commit: async (context, uow) =\u003e await uow.SaveChangesAsync(),\n        dispose: async (context, uow) =\u003e uow.Dispose()\n    ))\n    .Start();\n```\n\nBy the power of C# generics, `uow` passed to the `commit` and `dispose` functions above will have the same type as\nthe one returned from the `create` method.\n\n`context` will be the current `IMessageContext`, which is also statically accessible via `MessageContext.Current`,\nthis way enabling injection of your unit of work by using the message context to share it:\n```csharp\nConfigure.With(activator)\n    .Transport(t =\u003e t.Use(...))\n    .Options(o =\u003e o.EnableAsyncUnitOfWork(\n        create: async context =\u003e\n        {\n            var uow = new MyDbContext();\n            context.TransactionContext.Items[\"current-uow\"] = uow;\n            return uow;\n        },\n        commit: async (context, uow) =\u003e await uow.SaveChangesAsync(),\n        dispose: async (context, uow) =\u003e uow.Dispose()\n    ))\n    .Start();\n```\nand then you can configure your IoC container to be able to inject `MyDbContext` - e.g. with Microsoft Extensions Dependency Injection like this:\n\n```csharp\nservices.AddScoped(p =\u003e\n{\n    var context = p.GetService\u003cIMessageContext\u003e() \n                    ?? throw new InvalidOperationException(\"Cannot resolve db context outside of Rebus handler, sorry\");\n\n    return context.TransactionContext.Items.TryGetValue(\"current-uow\", out var result)\n        ? (MyDbContext)result\n        : throw new ArgumentException(\"Didn't find db context under 'current-uow' key in current context\");\n\n});\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frebus-org%2Frebus.unitofwork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frebus-org%2Frebus.unitofwork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frebus-org%2Frebus.unitofwork/lists"}