Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

IServiceContainer Interface

Provides a container for services.

Namespace:  System.ComponentModel.Design
Assembly:  System (in System.dll)

[<ComVisibleAttribute(true)>]
type IServiceContainer =  
    interface 
        interface IServiceProvider 
    end

The IServiceContainer type exposes the following members.

  NameDescription
Public methodAddService(Type, ServiceCreatorCallback)Adds the specified service to the service container.
Public methodAddService(Type, Object)Adds the specified service to the service container.
Public methodAddService(Type, ServiceCreatorCallback, Boolean)Adds the specified service to the service container, and optionally promotes the service to parent service containers.
Public methodAddService(Type, Object, Boolean)Adds the specified service to the service container, and optionally promotes the service to any parent service containers.
Public methodGetServiceGets the service object of the specified type. (Inherited from IServiceProvider.)
Public methodRemoveService(Type)Removes the specified service type from the service container.
Public methodRemoveService(Type, Boolean)Removes the specified service type from the service container, and optionally promotes the service to parent service containers.
Top

A service container is, by definition, a service provider. In addition to providing services, it also provides a mechanism for adding and removing services. Services are a foundation of the .NET Framework design-time architecture. Services provide design-time objects access to specific features and methods implemented by a service object that provides a service or services.

To obtain a service at design time, call the GetService method of a component sited in design mode. Designers and other objects can add or remove services at design time through the IDesignerHost interface.

Service containers can be contained by other service containers, forming a tree of service containers. By default, the IServiceContainer interface adds services to the closest service container. When a service is added, it can be added with instructions to promote it. When a service is promoted, it is added to any parent service container, on up until the top of the service container tree is reached. This allows a designer to provide a global service that other objects in the process can use.

The following code example contains the code for a Form that is configured to demonstrate the behavior of a network of linked service containers.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft