Επεξεργασία

Κοινή χρήση μέσω


IServiceContainer.AddService Method

Definition

Adds the specified service to the service container.

Overloads

AddService(Type, ServiceCreatorCallback)

Adds the specified service to the service container.

AddService(Type, Object)

Adds the specified service to the service container.

AddService(Type, ServiceCreatorCallback, Boolean)

Adds the specified service to the service container, and optionally promotes the service to parent service containers.

AddService(Type, Object, Boolean)

Adds the specified service to the service container, and optionally promotes the service to any parent service containers.

AddService(Type, ServiceCreatorCallback)

Adds the specified service to the service container.

public:
 void AddService(Type ^ serviceType, System::ComponentModel::Design::ServiceCreatorCallback ^ callback);
public void AddService (Type serviceType, System.ComponentModel.Design.ServiceCreatorCallback callback);
abstract member AddService : Type * System.ComponentModel.Design.ServiceCreatorCallback -> unit
Public Sub AddService (serviceType As Type, callback As ServiceCreatorCallback)

Parameters

serviceType
Type

The type of service to add.

callback
ServiceCreatorCallback

A callback object that is used to create the service. This allows a service to be declared as available, but delays the creation of the object until the service is requested.

Examples

The following example illustrates how to add a service to an IServiceContainer.

m_MyServiceContainer->AddService( Control::typeid, gcnew ServiceCreatorCallback( this, &Form1::CreateNewControl ) );
m_MyServiceContainer.AddService(typeof(Control),
                new ServiceCreatorCallback(this.CreateNewControl));
m_MyServiceContainer.AddService(GetType(Control), New ServiceCreatorCallback( _
          AddressOf CreateNewControl))

Applies to

AddService(Type, Object)

Adds the specified service to the service container.

public:
 void AddService(Type ^ serviceType, System::Object ^ serviceInstance);
public void AddService (Type serviceType, object serviceInstance);
abstract member AddService : Type * obj -> unit
Public Sub AddService (serviceType As Type, serviceInstance As Object)

Parameters

serviceType
Type

The type of service to add.

serviceInstance
Object

An instance of the service type to add. This object must implement or inherit from the type indicated by the serviceType parameter.

Examples

The following example illustrates how to add a service to an IServiceContainer.

m_MyServiceContainer->AddService( Control::typeid, sender );
m_MyServiceContainer.AddService(typeof(Control), sender);
m_MyServiceContainer.AddService(GetType(Control), sender)

Applies to

AddService(Type, ServiceCreatorCallback, Boolean)

Adds the specified service to the service container, and optionally promotes the service to parent service containers.

public:
 void AddService(Type ^ serviceType, System::ComponentModel::Design::ServiceCreatorCallback ^ callback, bool promote);
public void AddService (Type serviceType, System.ComponentModel.Design.ServiceCreatorCallback callback, bool promote);
abstract member AddService : Type * System.ComponentModel.Design.ServiceCreatorCallback * bool -> unit
Public Sub AddService (serviceType As Type, callback As ServiceCreatorCallback, promote As Boolean)

Parameters

serviceType
Type

The type of service to add.

callback
ServiceCreatorCallback

A callback object that is used to create the service. This allows a service to be declared as available, but delays the creation of the object until the service is requested.

promote
Boolean

true to promote this request to any parent service containers; otherwise, false.

Applies to

AddService(Type, Object, Boolean)

Adds the specified service to the service container, and optionally promotes the service to any parent service containers.

public:
 void AddService(Type ^ serviceType, System::Object ^ serviceInstance, bool promote);
public void AddService (Type serviceType, object serviceInstance, bool promote);
abstract member AddService : Type * obj * bool -> unit
Public Sub AddService (serviceType As Type, serviceInstance As Object, promote As Boolean)

Parameters

serviceType
Type

The type of service to add.

serviceInstance
Object

An instance of the service type to add. This object must implement or inherit from the type indicated by the serviceType parameter.

promote
Boolean

true to promote this request to any parent service containers; otherwise, false.

Applies to