Some ideas

Oct 14, 2008 at 10:21 PM
Edited Oct 14, 2008 at 10:24 PM
Hello.

1. Method GetInstance<TService> is redundant, because it can be implemented outside (in form of static or extension method) and all internal implementations will be very similar.
2. Throwing exception when service not found prevent discovering services, that is not mandatory, and lead to use exceptions to detect service absence. IMHO, null return in GetService()/GetService<T>() and external (extension) methods GetRequiredService()/GetRequiredService<T>() is better variant.
3. Retrieving all available service instances is not required in many use cases. Moreover, in some scenarios (lazy instantiation, for example), atempt to do it may result a huge performance overhead.
4. Not all locators support keyed instances. It would be better design, if keyed version of methods will be separated to a different interface, that inherits from original.
Developer
Oct 14, 2008 at 11:44 PM
1. Can't use extension methods, we need to support VS 2005. Separate static helper class would be too jarring. The base class provided with the library provides the stock implementation of the overloads, so you don't need to do it.
2. If you want to discover if a service is registered without throwing an exception, do GetAllInstances and check for an empty collection.
3. Just because it's not required in some use cases doesn't mean that nobody should ever do it.
4. Locator implementations are free to ignore the keys.