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.

C#
public void AddService(Type serviceType, System.ComponentModel.Design.ServiceCreatorCallback callback);

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.

C#
m_MyServiceContainer.AddService(typeof(Control),
                new ServiceCreatorCallback(this.CreateNewControl));

See also

Applies to

.NET 10 ja muut versiot
Tuote Versiot
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddService(Type, Object)

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

Adds the specified service to the service container.

C#
public void AddService(Type serviceType, object serviceInstance);

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.

C#
m_MyServiceContainer.AddService(typeof(Control), sender);

See also

Applies to

.NET 10 ja muut versiot
Tuote Versiot
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddService(Type, ServiceCreatorCallback, Boolean)

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

Adds the specified service to the service container.

C#
public virtual void AddService(Type serviceType, System.ComponentModel.Design.ServiceCreatorCallback callback, bool promote);
C#
public void AddService(Type serviceType, System.ComponentModel.Design.ServiceCreatorCallback callback, bool promote);

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

.NET 10 ja muut versiot
Tuote Versiot
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

AddService(Type, Object, Boolean)

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

Adds the specified service to the service container.

C#
public virtual void AddService(Type serviceType, object serviceInstance, bool promote);
C#
public void AddService(Type serviceType, object serviceInstance, bool promote);

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

.NET 10 ja muut versiot
Tuote Versiot
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1