rebus-org / Rebus.ServiceProvider

:bus: Microsoft Extensions Dependency Injection container adapter for Rebus
https://mookid.dk/category/rebus
Other
68 stars 32 forks source link

NetCoreServiceCollectionContainerAdapter builds service provider every time & bus must be started before service registration is complete #4

Closed trreeves closed 7 years ago

trreeves commented 7 years ago

I have just started to add Rebus support to a fairly large commercial system, comprising of a lot of de-coupled components that will each perform service registrations and initialization steps during the app startup.

There appear to be 2 big problems with the current NetCoreServiceCollectionContainerAdapter that have prevented me from using it:

  1. The service provider is built every time a message is handled (on every call to IContainerAdapter.GetHandlers(...). As well as performance concerns, it also breaks any singleton lifestyle behavior required by any application services (that are injected into handlers). You also couldn't configure a handler to be a singleton if you wanted.

  2. The IBus must be started before it is registered in the service collection, at which point, it will start to handle messages - and so potentially create handlers that could require services that are not yet registered in the service collection.

I have written a solution to this for my current project, out of necessity, and also have made it available in my fork here: https://github.com/trevorreeves/Rebus.ServiceProvider. Let me know if you are interested, and any thoughts on it, and I'll create a PR. Happy to develop it further based on any input you have, plus develop the readme. I have provided some tests, but haven't managed to successfully get Nunit running them yet... can put in more time if it's a go-er.

Cheers

Trevor.

mookid8000 commented 7 years ago

Hi Trevor, sorry for taking so long to get back to you ...

I am definitely interested! Please send PR 😄

trreeves commented 7 years ago

See #5

mookid8000 commented 7 years ago

wasn't this issue fixed?

trreeves commented 7 years ago

yep.