Editare

Partajați prin


ServiceContainer.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.

AddService(Type, Object, Boolean)

Adds the specified service to the service container.

AddService(Type, ServiceCreatorCallback)

Source:
ServiceContainer.cs
Source:
ServiceContainer.cs
Source:
ServiceContainer.cs

Adds the specified service to the service container.

public:
 virtual 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
override this.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 can create the service. This allows a service to be declared as available, but delays creation of the object until the service is requested.

Implements

Exceptions

serviceType or callback is null.

A service of type serviceType already exists in the container.

Examples

The following example illustrates how to add a service to a ServiceContainer.

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))

See also

Applies to

AddService(Type, Object)

Source:
ServiceContainer.cs
Source:
ServiceContainer.cs
Source:
ServiceContainer.cs

Adds the specified service to the service container.

public:
 virtual void AddService(Type ^ serviceType, System::Object ^ serviceInstance);
public void AddService (Type serviceType, object serviceInstance);
abstract member AddService : Type * obj -> unit
override this.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 to add. This object must implement or inherit from the type indicated by the serviceType parameter.

Implements

Exceptions

serviceType or serviceInstance is null.

A service of type serviceType already exists in the container.

Examples

The following example illustrates how to add a service to a ServiceContainer.

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

See also

Applies to

AddService(Type, ServiceCreatorCallback, Boolean)

Source:
ServiceContainer.cs
Source:
ServiceContainer.cs
Source:
ServiceContainer.cs

Adds the specified service to the service container.

public:
 virtual void AddService(Type ^ serviceType, System::ComponentModel::Design::ServiceCreatorCallback ^ callback, bool promote);
public virtual 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
override this.AddService : Type * System.ComponentModel.Design.ServiceCreatorCallback * bool -> unit
Public Overridable Sub AddService (serviceType As Type, callback As ServiceCreatorCallback, promote As Boolean)
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 can create the service. This allows a service to be declared as available, but delays creation of the object until the service is requested.

promote
Boolean

true if this service should be added to any parent service containers; otherwise, false.

Implements

Exceptions

serviceType or callback is null.

A service of type serviceType already exists in the container.

See also

Applies to

AddService(Type, Object, Boolean)

Source:
ServiceContainer.cs
Source:
ServiceContainer.cs
Source:
ServiceContainer.cs

Adds the specified service to the service container.

public:
 virtual void AddService(Type ^ serviceType, System::Object ^ serviceInstance, bool promote);
public virtual void AddService (Type serviceType, object serviceInstance, bool promote);
public void AddService (Type serviceType, object serviceInstance, bool promote);
abstract member AddService : Type * obj * bool -> unit
override this.AddService : Type * obj * bool -> unit
Public Overridable Sub AddService (serviceType As Type, serviceInstance As Object, promote As Boolean)
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 if this service should be added to any parent service containers; otherwise, false.

Implements

Exceptions

serviceType or serviceInstance is null.

A service of type serviceType already exists in the container.

See also

Applies to