Daniel - I agree so strongly I almost need to type this entire email
in CAPS.
There are a range of use cases where this library will be handy
though.
E.g.
ASP.NET MVC depends on IControllerFactory.
It also ships with an optional ServiceLocatorControllerFactory.
SLCF depends on the generic IServiceLocator, so if you have an
implementation for your container you can do something like:
x.ControllerFactory = new ServiceLocatorControllerFactory(new
AutofacServiceLocator(myContainer));
This just cuts down on the code that has to be written to support new
frameworks.
The catch is that the framework must not depend on the generic service
locator - the only place that the coupling is acceptable is in the
same place we're currently doing it - a small, throwaway, independent
adapter class that can be used to turn calls on a specific interface
to calls on a generic one.
Glenn and I have had a lot of discussions lately about how to
discourage people from referencing IServiceLocator when really they
should reference a domain-specific registry or factory interface.
It is scary that 90+% of the use cases for this are *abuse*, but done
correctly the other 10% of use cases will really help encourage
diversity of choice in terms of IoC containers.
Once again, I agree with your point so strongly that I was initially
against even THINKING about creating such a thing, but now with some
time to reflect I've concluded that we shouldn't try to protect users
from themselves, and as always it is up to the user to get informed
and use this correctly.
Hope this wasn't too much of a rant for this generally quiet list :)
On Oct 2, 12:26 pm, "Daniel Cazzulino" <
dan...@cazzulino.com> wrote:
> I think IServiceLocator is a bad idea, so I wouldn't make the slightest
> change to Autofac to add any special support for it.
>
> DI is about NOT doing opaque service locator injection...
>
> On Thu, Oct 2, 2008 at 1:07 PM, Nicholas Blumhardt <
>
>
nicholas.blumha...@gmail.com> wrote:
> > Hi Justin!
>
> > I have been thinking about this too.
>
> > Looping through registrations is possible (perhaps we could offer a
> > configuration parameter?) but my preference would be to translate these
> > calls into requests for IEnumerable<T> on the container.
>
> > My reasoning is that this matches Autofac's "opt-in" collection semantics.
>
> > Keen to discuss those semantics in detail at some point (when I have some
> > more time.)
>
> > Hey are you in Redmond? I'd love to catch up and say "hi!"
>
> > Cheers,
>
> > Nick
>
> > On Thu, Oct 2, 2008 at 1:37 AM, Justin Rudd <
justin.r...@gmail.com> wrote:
>
> >> Chris Tavares just posted about the common service locator interface -
> >>
http://www.tavaresstudios.com/Blog/post.aspx?id=32a656f5-e908-4a25-b6....