MediatR icon indicating copy to clipboard operation
MediatR copied to clipboard

Hostedservice as a notification handler?

Open RollsChris opened this issue 4 years ago • 3 comments

Hi just wondering if it's possible to use a hostedservice as a notification handler? At the moment it's being added twice and uses the wrong one i.e. the one without startasync. Thanks

RollsChris avatar Nov 23 '20 20:11 RollsChris

All the handlers are added as Transient by default, so even if your hosted service is running in the background Mediatr would create a new instance. It would be interesting/nice to have some extension that might be able to separate these, e.g. services.RegisterMediatrHandlersThatInherit<IHostedService>(ServiceLifetime.Singleton).AsImplementedInterfaces()

brendankowitz avatar Nov 30 '20 22:11 brendankowitz

Hey thanks for the response.. yes it would. Would love to help.. but i wouldn't know where to start

RollsChris avatar Dec 02 '20 12:12 RollsChris

I have created a library for this MediatR.Courier. It lets you to dynamically subscribe to notifications.

KuraiAndras avatar Mar 05 '21 10:03 KuraiAndras