Support for scoped Consumers
See original GitHub issueIn some cases the consumer (IConsumer<T>
) needs to inject scoped dependencies (like the EF DbContext) hence needs to be registered as scoped in the DI container. As a result, the SMB should create a scope and resolve such consumers in that scoped container. The scope should be bound to each message which represents a transaction or a unit of work.
Also related to #34 .
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (6 by maintainers)
Top Results From Across the Web
c# - How to initialize scoped dependencies for consumers ...
There's two facets to consider: 1) are filters registered as services/pulled from the service collection when using the ASP.
Read more >Dependency injection guidelines - .NET
Use scopes to control the lifetimes of services. Scopes aren't hierarchical, and there's no special connection among scopes.
Read more >Scoped Middleware Filters
Supported Filter Contexts. Scope filters are added using one of the following methods, which are specific to the filter context type. Type, Usage ......
Read more >Are Scoped Apps of any value to customers?
Solved: So I've built Scoped Apps as a member of the TPP, so the value statement is clear for ServiceNow customers buying apps, ......
Read more >Injection scopes | NestJS - A progressive Node.js framework
Each consumer that injects a transient provider will receive a new, dedicated instance. Hint Using singleton scope is recommended for most use cases....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I totally get that this is a complicated matter, also due to the other DI libraries that SMB supports 😃
My setup on a high level is the following:
Right now I have circumvented the problem by registering a whole lot of things as Singleton, but I would prefer them to be Scoped.
When I get a bit of time I can try to make a minimal repro of the setup to give you something to debug from.
Exactly, spot on 😃
Anyway thanks for this awesome library.
Hello, the feature has been implemented.
Any feedback on the proposed will be much appreciated!
A preview is available on nuget: https://www.nuget.org/packages/SlimMessageBus.Host/1.12.0-rc1 https://www.nuget.org/packages/SlimMessageBus.Host.Kafka/1.12.0-rc1 https://www.nuget.org/packages/SlimMessageBus.Host.AzureServiceBus/1.12.0-rc1 https://www.nuget.org/packages/SlimMessageBus.Host.Redis/1.12.0-rc1
The docs are here: https://github.com/zarusz/SlimMessageBus/blob/feature/scoped_consumers/docs/intro.md#per-message-di-container-scope https://github.com/zarusz/SlimMessageBus/blob/feature/scoped_consumers/docs/provider_memory.md#per-message-di-scope