This project is read-only.

GetService() - non explicit implementation of IServiceProvider

Oct 14, 2013 at 12:22 AM
I had a few situations in which I wanted the GetService() instead the GetInstance<>() behavior (e.g. return null if type is not supported) and I had to write something like:
Why was the IServiceProvider interface explicitly implemented? I fear some users might also require the GetService() behavior but do not directly discover this option since it is not directly visible in intelli-sense.
Oct 14, 2013 at 7:38 AM
Edited Oct 14, 2013 at 9:28 PM
The GetService method is mainly needed for integration scenarios. Although important to have, I didn't want it to clutter the main API. I didn't want developers to call it, because in most cases you should call GetInstance and I didn't find the name GetService very expressive. Still, for compatibility, it is important for the Container to implement IServiceProvider. ThThat's why it's implemented explicitly. A better method name would be GetInstanceOrNull or TryGetInstance, but again, I wanted to add this to he main API. This was a compromise.
Marked as answer by dot_NET_Junkie on 3/2/2014 at 11:12 AM