Is the IServiceProvider basically just a generic interface for any IOC container, or is it used for a specific framework? I’m rolling my own light weight IOC container and I am wanting to know if I should implement it. Are there any other interfaces that I should implement? I’m not really interested in either MEF or Unity. I’ve used both extensively and they don’t really work for my current project.
Is the IServiceProvider basically just a generic interface for any IOC container, or is
Share
IServiceProvideris an imported (or perhaps held-over) COM interface that is intended to be used for private features in the context of the object whom you interrogate for a Service. The term ‘Service’ is applied rather loosely here, it originally meant any COM object that could be returned based upon what GUID is given.IServiceProvider @ MSDN (.NET reference)
IServiceProviderImpl Class @ MSDN (C++ ATL reference)
In .NET, you don’t need to implement it unless you have a client that specifically supports it, and in many cases you won’t need to add yet another level of indirection that is implied by using
IServiceProvider. Also, you can devise your own scheme to share common objects or implement other use patterns based upon IoC / Dependency Injection that are more flexible or more rigid as dictated by your needs.One good historical context for
IServiceProvideris the IE Browser Plugin Spec. Here, it is used to allow plugin components to use Browser Host features in-context. In a COM context, this interface is useful because it hides the details of instantiation and also can be used as part of a object construction and utilization strategy to avoid reference loops.WebBrowser Customization (Part 2) @ MSDN