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.

How to Create MassTransit Message Interceptor (Observer) with Scoped Lifetime

See original GitHub issue

We can setup Consume Observer using following way busControl.ConnectConsumeObserver(container.GetInstance<MessageConsumerInterceptor>());

I want to apply Scope lifestyle to MessageConsumerInterceptor so that I can fill/ initialize some object before consuming or handling the message. And I can access that filled object through the message handler or consumer. Now how I can achieve this using MassTransit?

I am expecting your help or possible suggestion.

Thanks in advance. Also asked in stackoverflow

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
TerraVenilcommented, Mar 10, 2018

Please ignore my previous message I was able to solve issues with scoped instances myself. It was mistake from my side rely on issue with creation instances from different threads. So I have updated test and enahnce ASP.NET Core DI extension with scope method. Please review if you find that useful https://github.com/MassTransit/MassTransit/pull/1076.

0reactions
TerraVenilcommented, Mar 9, 2018

I think using middleware is more appropriate to manipulation with contextual inforamtion which scoped per consumed message. For that purpose I use ASP.NET Core DI and you can find example by link https://github.com/TerraVenil/MassTransit/tree/ResolveScopedInstance. On this point I agree with @hasibul2363 that due to different threads for IFilter and IConsumer scoped information is loosing. Besides I don’t think that it’s good idea to pass IServiceProvider to Filter/Specification to resolve scoped instances so suggested previous GetOrAddPayload/TryGetPayload works for my case BUT is there are way to prevent duplication of TryGetPayload to resolve instance and move that responsibility to IServiceProvider?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Create MassTransit Message Interceptor (Observer ...
I have tried with Middleware-Filter but no luck. It is giving exception that i cannot use Scoped lifetime object outside of context. It...
Read more >
How to Create MassTransit Message Interceptor (Observer ...
We can setup Consume Observer using following way busControl.ConnectConsumeObserver(container.GetInstance<MessageConsumerInterceptor>());.
Read more >
Observability
Lifetime Observers. MassTransit supports several message observers allowing received, consumed, sent, and published messages to be monitored. There is a bus ...
Read more >
Messaging through a service bus in .NET using MassTransit ...
In this post we'll see how to intercept messages both in the publisher and receiver. The message observers. Messages can be intercepted and ......
Read more >
Climate Change Draft Scoping Plan Appendices Contents
To be included with Draft Scoping Plan Supplemental Analysis ... greenhouse gas emission reporting programs and make reasonable efforts to.
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