ServiceCollectionServiceExtensions.AddSingleton 方法

定义

重载

AddSingleton(IServiceCollection, Type)

serviceType 中指定类型的单一实例服务添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in serviceType to the specified IServiceCollection.

AddSingleton(IServiceCollection, Type, Func<IServiceProvider,Object>)

使用 serviceType 中指定的中心将 implementationFactory 中指定类型的单一实例服务添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in serviceType with a factory specified in implementationFactory to the specified IServiceCollection.

AddSingleton(IServiceCollection, Type, Object)

serviceType 中指定类型的单一实例服务和 implementationInstance 中指定的实例添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in serviceType with an instance specified in implementationInstance to the specified IServiceCollection.

AddSingleton(IServiceCollection, Type, Type)

serviceType 中指定类型的单一实例服务和 implementationType 中指定类型的实现添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in serviceType with an implementation of the type specified in implementationType to the specified IServiceCollection.

AddSingleton<TService,TImplementation>(IServiceCollection, Func<IServiceProvider,TImplementation>)

使用 TService 中指定的中心将 TImplementation 中指定类型的单一实例服务和 implementationFactory 中指定类型的实现添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in TService with an implementation type specified in TImplementation using the factory specified in implementationFactory to the specified IServiceCollection.

AddSingleton<TService,TImplementation>(IServiceCollection)

TService 中指定类型的单一实例服务和 TImplementation 中指定类型的实现添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in TService with an implementation type specified in TImplementation to the specified IServiceCollection.

AddSingleton<TService>(IServiceCollection)

TService 中指定类型的单一实例服务添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in TService to the specified IServiceCollection.

AddSingleton<TService>(IServiceCollection, Func<IServiceProvider,TService>)

使用 TService 中指定的中心将 implementationFactory 中指定类型的单一实例服务添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in TService with a factory specified in implementationFactory to the specified IServiceCollection.

AddSingleton<TService>(IServiceCollection, TService)

TService 中指定类型的单一实例服务和 implementationInstance 中指定的实例添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in TService with an instance specified in implementationInstance to the specified IServiceCollection.

AddSingleton(IServiceCollection, Type)

serviceType 中指定类型的单一实例服务添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in serviceType to the specified IServiceCollection.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Type ^ serviceType);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType);
static member AddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type -> Microsoft.Extensions.DependencyInjection.IServiceCollection
<Extension()>
Public Function AddSingleton (services As IServiceCollection, serviceType As Type) As IServiceCollection

参数

services
IServiceCollection

要向其中添加服务的 IServiceCollectionThe IServiceCollection to add the service to.

serviceType
Type

要注册的服务类型和要使用的实现。The type of the service to register and the implementation to use.

返回

完成操作后对此实例的引用。A reference to this instance after the operation has completed.

另请参阅

AddSingleton(IServiceCollection, Type, Func<IServiceProvider,Object>)

使用 serviceType 中指定的中心将 implementationFactory 中指定类型的单一实例服务添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in serviceType with a factory specified in implementationFactory to the specified IServiceCollection.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Type ^ serviceType, Func<IServiceProvider ^, System::Object ^> ^ implementationFactory);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType, Func<IServiceProvider,object> implementationFactory);
static member AddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * Func<IServiceProvider, obj> -> Microsoft.Extensions.DependencyInjection.IServiceCollection
<Extension()>
Public Function AddSingleton (services As IServiceCollection, serviceType As Type, implementationFactory As Func(Of IServiceProvider, Object)) As IServiceCollection

参数

services
IServiceCollection

要向其中添加服务的 IServiceCollectionThe IServiceCollection to add the service to.

serviceType
Type

要注册的服务类型。The type of the service to register.

implementationFactory
Func<IServiceProvider,Object>

用于创建服务的工厂。The factory that creates the service.

返回

完成操作后对此实例的引用。A reference to this instance after the operation has completed.

另请参阅

AddSingleton(IServiceCollection, Type, Object)

serviceType 中指定类型的单一实例服务和 implementationInstance 中指定的实例添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in serviceType with an instance specified in implementationInstance to the specified IServiceCollection.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Type ^ serviceType, System::Object ^ implementationInstance);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType, object implementationInstance);
static member AddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * obj -> Microsoft.Extensions.DependencyInjection.IServiceCollection
<Extension()>
Public Function AddSingleton (services As IServiceCollection, serviceType As Type, implementationInstance As Object) As IServiceCollection

参数

services
IServiceCollection

要向其中添加服务的 IServiceCollectionThe IServiceCollection to add the service to.

serviceType
Type

要注册的服务类型。The type of the service to register.

implementationInstance
Object

服务实例。The instance of the service.

返回

完成操作后对此实例的引用。A reference to this instance after the operation has completed.

另请参阅

AddSingleton(IServiceCollection, Type, Type)

serviceType 中指定类型的单一实例服务和 implementationType 中指定类型的实现添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in serviceType with an implementation of the type specified in implementationType to the specified IServiceCollection.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Type ^ serviceType, Type ^ implementationType);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Type serviceType, Type implementationType);
static member AddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * Type -> Microsoft.Extensions.DependencyInjection.IServiceCollection
<Extension()>
Public Function AddSingleton (services As IServiceCollection, serviceType As Type, implementationType As Type) As IServiceCollection

参数

services
IServiceCollection

要向其中添加服务的 IServiceCollectionThe IServiceCollection to add the service to.

serviceType
Type

要注册的服务类型。The type of the service to register.

implementationType
Type

服务的实现类型。The implementation type of the service.

返回

完成操作后对此实例的引用。A reference to this instance after the operation has completed.

另请参阅

AddSingleton<TService,TImplementation>(IServiceCollection, Func<IServiceProvider,TImplementation>)

使用 TService 中指定的中心将 TImplementation 中指定类型的单一实例服务和 implementationFactory 中指定类型的实现添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in TService with an implementation type specified in TImplementation using the factory specified in implementationFactory to the specified IServiceCollection.

public:
generic <typename TService, typename TImplementation>
 where TService : class where TImplementation : class, TService[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Func<IServiceProvider ^, TImplementation> ^ implementationFactory);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton<TService,TImplementation> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Func<IServiceProvider,TImplementation> implementationFactory) where TService : class where TImplementation : class, TService;
static member AddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Func<IServiceProvider, #'Service> -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Service : null)
<Extension()>
Public Function AddSingleton(Of TService As Class, TImplementation As Class) (services As IServiceCollection, implementationFactory As Func(Of IServiceProvider, TImplementation)) As IServiceCollection

类型参数

TService

要添加的服务类型。The type of the service to add.

TImplementation

要使用的实现的类型。The type of the implementation to use.

参数

services
IServiceCollection

要向其中添加服务的 IServiceCollectionThe IServiceCollection to add the service to.

implementationFactory
Func<IServiceProvider,TImplementation>

用于创建服务的工厂。The factory that creates the service.

返回

完成操作后对此实例的引用。A reference to this instance after the operation has completed.

另请参阅

AddSingleton<TService,TImplementation>(IServiceCollection)

TService 中指定类型的单一实例服务和 TImplementation 中指定类型的实现添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in TService with an implementation type specified in TImplementation to the specified IServiceCollection.

public:
generic <typename TService, typename TImplementation>
 where TService : class where TImplementation : class, TService[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton<TService,TImplementation> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services) where TService : class where TImplementation : class, TService;
static member AddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Service : null)
<Extension()>
Public Function AddSingleton(Of TService As Class, TImplementation As Class) (services As IServiceCollection) As IServiceCollection

类型参数

TService

要添加的服务类型。The type of the service to add.

TImplementation

要使用的实现的类型。The type of the implementation to use.

参数

services
IServiceCollection

要向其中添加服务的 IServiceCollectionThe IServiceCollection to add the service to.

返回

完成操作后对此实例的引用。A reference to this instance after the operation has completed.

另请参阅

AddSingleton<TService>(IServiceCollection)

TService 中指定类型的单一实例服务添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in TService to the specified IServiceCollection.

public:
generic <typename TService>
 where TService : class[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton<TService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services) where TService : class;
static member AddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Service : null)
<Extension()>
Public Function AddSingleton(Of TService As Class) (services As IServiceCollection) As IServiceCollection

类型参数

TService

要添加的服务类型。The type of the service to add.

参数

services
IServiceCollection

要向其中添加服务的 IServiceCollectionThe IServiceCollection to add the service to.

返回

完成操作后对此实例的引用。A reference to this instance after the operation has completed.

另请参阅

AddSingleton<TService>(IServiceCollection, Func<IServiceProvider,TService>)

使用 TService 中指定的中心将 implementationFactory 中指定类型的单一实例服务添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in TService with a factory specified in implementationFactory to the specified IServiceCollection.

public:
generic <typename TService>
 where TService : class[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Func<IServiceProvider ^, TService> ^ implementationFactory);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton<TService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Func<IServiceProvider,TService> implementationFactory) where TService : class;
static member AddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * Func<IServiceProvider, 'Service (requires 'Service : null)> -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Service : null)
<Extension()>
Public Function AddSingleton(Of TService As Class) (services As IServiceCollection, implementationFactory As Func(Of IServiceProvider, TService)) As IServiceCollection

类型参数

TService

要添加的服务类型。The type of the service to add.

参数

services
IServiceCollection

要向其中添加服务的 IServiceCollectionThe IServiceCollection to add the service to.

implementationFactory
Func<IServiceProvider,TService>

用于创建服务的工厂。The factory that creates the service.

返回

完成操作后对此实例的引用。A reference to this instance after the operation has completed.

另请参阅

AddSingleton<TService>(IServiceCollection, TService)

TService 中指定类型的单一实例服务和 implementationInstance 中指定的实例添加到指定的 IServiceCollection 中。Adds a singleton service of the type specified in TService with an instance specified in implementationInstance to the specified IServiceCollection.

public:
generic <typename TService>
 where TService : class[System::Runtime::CompilerServices::Extension]
 static Microsoft::Extensions::DependencyInjection::IServiceCollection ^ AddSingleton(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, TService implementationInstance);
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddSingleton<TService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, TService implementationInstance) where TService : class;
static member AddSingleton : Microsoft.Extensions.DependencyInjection.IServiceCollection * 'Service -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Service : null)
<Extension()>
Public Function AddSingleton(Of TService As Class) (services As IServiceCollection, implementationInstance As TService) As IServiceCollection

类型参数

TService

参数

services
IServiceCollection

要向其中添加服务的 IServiceCollectionThe IServiceCollection to add the service to.

implementationInstance
TService

服务实例。The instance of the service.

返回

完成操作后对此实例的引用。A reference to this instance after the operation has completed.

另请参阅

适用于