question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for scoped Consumers

See original GitHub issue

In 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
novercommented, Jan 28, 2021

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:

  • Aspnet core 5.0 WebApi
  • Scoped background worker that runs a WebSocket client to consume events from an external system. Each “handler” for different message types are executed as separate threads on the thread-pool
  • Then I want those handlers to be able to send domain events to the platform (which is a monolith now to de-complicate some matters), thus using the InMemory provider
  • I experience the lockups in the background service worker when emitting the events.

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.

Effectively this gives a per-message scope which I guess is the ask of this issue.

Exactly, spot on 😃

Anyway thanks for this awesome library.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found