Skip to content

How does dependency injection work in observers? #1467

Answered by woksin
Petteroe asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, the problem is that the Observers wrongfully uses the root service provider and not a scoped one when resolving the services. Your IPublishEndpoint is, probably correctly, registered as a scoped service which by design cannot be resolved from the root container.

What you can do as a work around is to instead inject the IServiceProvider and in the Submitted method you can create and dispose your own service provider scope and use that to resolve your dependency.

However as I said this is a fault in Chronicle and should be addressed

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by woksin
Comment options

You must be logged in to vote
1 reply
@woksin
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants