Redundant handler and mapper registrations in consumer projects #2395
-
Hi guys! I obviously have problem understanding the registrations of async handlers and mappers when I have IHostedService that has to build and run the Dispatcher. So, I have regular service registration in my Worker console project, building IServiceCollection. Here I must .AddBrighter() and register async handlers and mappers explicitly (or use AutoFromAssemblies - which I'd like to avoid btw). Then, in my IHostedService I'm building up the Dispatcher with CommandProcessorFactory, passing the SubscriberRegistry where I had to register my handlers again, and to the DispatcherBuilder passing another MessageMapper with same map like I had in the service registration in the beginning. Only if I do the registrations in both places (or use AutoFromAssemblies), the worker starts consuming messages from the bus and instantiating handlers. I'd really like to avoid redundant registrations if possible. Please let me know what I'm doing wrong here. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
@preardon here ^^^^ |
Beta Was this translation helpful? Give feedback.
-
@nesbo This is a problem with the way that we build the underlying Command Processor and Service Activator. Both are doing registration of these items. It's a bug, and I am going to raise it as an issue. |
Beta Was this translation helpful? Give feedback.
-
Coming back to this I think @nesbo just needs use the dispatcher from the servicecollection in his Ihostedservice, like how we do in our extension |
Beta Was this translation helpful? Give feedback.
and you can just use what we built like this
Brighter/samples/RedisTaskQueue/GreetingsReceiver/Program.cs
Line 55 in d5c946e