MediatR
MediatR copied to clipboard
Hostedservice as a notification handler?
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
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()
Hey thanks for the response.. yes it would. Would love to help.. but i wouldn't know where to start
I have created a library for this MediatR.Courier. It lets you to dynamically subscribe to notifications.