Generic GetService<T> and GetServices<T> extension methods for the System.IServiceProvider interface.
IServiceProvider serviceProvider = HoweverYouGetAnInstance();
// instead of this
// ISomeInterface implementation = serviceProvider.GetService(typeof(ISomeInterface))
// use the extension
ISomeInterface implementation = serviceProvider.GetService<ISomeInterface>();
IServiceProvider serviceProvider = HoweverYouGetAnInstance();
// get a multiply-registered interface without any overhead
IEnumerable<ISomeInterface> implementations = serviceProvider.GetServices<ISomeInterface>();
This software is subject to the terms of the Microsoft Public License (Ms-PL).