-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Providing greater control over DI lifetime scope #17
Conversation
Changed AutofacDependencyResolver ctor to take ILifetimeScope instead of IContainer, added ctor injection of IDependencyResolver to Mediator
Sure, I originally intended to duplicate the "BasicExample" tests, using Autofac, instead of StructureMap, but then I hit a bit of a wall on one part.
|
I had already converted my "BasicExample" to autofac and also had issues with the "PingALing" test. I had know idea that was the issue. Also why are you setting AutofacDependencyResolver and Mediator to InstancePerLifetimeScope? Or at least how did you know these should use InstancePerLifetimeScope instead of the default? |
@zachariahyoung, check out this gist for exploratory tests to demonstrate (if you grab my pull request or my fork, paste it into there and they should run as expected).
I set them up to InstancePerLifetimeScope primarily to demonstrate that it could be done -- my initial objective was to provide greater control over the scope that ShortBus uses to resolve message handlers and their dependencies. That having been said, my initial objective stems from two issues I saw with default/previous behavior of ShortBus & ShortBus.Autofac: using DependencyResolver as a Singleton via static dependency, as well as the use of Autofac.IContainer in AutofacDependencyResolver. This had a couple of implications:
So to wrap up, the changes I made were intended to prevent the mediator from being bound to that Singleton scope/global state. Effectively, the mediator (and it’s dependency resolver) went from Singleton scoped to instance per lifetime scope (or whichever scope you choose to configure). God that was a lot of typing... I hope that makes sense at all. |
Providing greater control over DI lifetime scope
Autofac is exotic |
It can get pretty interesting, that's for sure |
Changed AutofacDependencyResolver ctor to take ILifetimeScope instead of IContainer, providing greater flexibility, as IContainer can only be used at the root level in Autofac.
Also, injected IDependencyResolver into Mediator ctor, to allow mediator to resolve dependencies from various lifetime scopes, as determined by consuming devs.