共用方式為


ServiceCollectionServiceExtensions.AddSingleton 方法

定義

多載

AddSingleton(IServiceCollection, Type, Object)

serviceType 中指定類型的單一服務,以及 implementationInstance 中指定的執行個體,新增至指定的 IServiceCollection

AddSingleton(IServiceCollection, Type, Type)

serviceType 中指定類型的單一服務,以及在 implementationType 中指定類型的實作,新增至指定的 IServiceCollection

AddSingleton(IServiceCollection, Type)

serviceType 中指定類型的單一服務,新增至指定的 IServiceCollection

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

serviceType 中指定類型的單一服務,以及 implementationFactory 中指定的 Factory,新增至指定的 IServiceCollection

AddSingleton<TService,TImplementation>(IServiceCollection)

TService 中指定類型的單一服務,以及在 TImplementation 中指定的實作類型,新增至指定的 IServiceCollection

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

使用 implementationFactory 中指定的 Factory,將 TService 中指定類型的單一服務,以及 TImplementation 中指定的實作類型,新增至指定的 IServiceCollection

AddSingleton<TService>(IServiceCollection)

TService 中指定類型的單一服務,新增至指定的 IServiceCollection

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

TService 中指定類型的單一服務,以及 implementationFactory 中指定的 Factory,新增至指定的 IServiceCollection

AddSingleton<TService>(IServiceCollection, TService)

TService 中指定類型的單一服務,以及 implementationInstance 中指定的執行個體,新增至指定的 IServiceCollection

AddSingleton(IServiceCollection, Type, Object)

來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs

serviceType 中指定類型的單一服務,以及 implementationInstance 中指定的執行個體,新增至指定的 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

要新增服務的 IServiceCollection

serviceType
Type

要註冊的服務類型。

implementationInstance
Object

服務的執行個體。

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

AddSingleton(IServiceCollection, Type, Type)

來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs

serviceType 中指定類型的單一服務,以及在 implementationType 中指定類型的實作,新增至指定的 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

要新增服務的 IServiceCollection

serviceType
Type

要註冊的服務類型。

implementationType
Type

服務的實作類型。

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

AddSingleton(IServiceCollection, Type)

來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs

serviceType 中指定類型的單一服務,新增至指定的 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

要新增服務的 IServiceCollection

serviceType
Type

要註冊的服務類型,以及要使用的實作。

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

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

來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs

serviceType 中指定類型的單一服務,以及 implementationFactory 中指定的 Factory,新增至指定的 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

要新增服務的 IServiceCollection

serviceType
Type

要註冊的服務類型。

implementationFactory
Func<IServiceProvider,Object>

建立服務的 Factory。

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

AddSingleton<TService,TImplementation>(IServiceCollection)

來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs

TService 中指定類型的單一服務,以及在 TImplementation 中指定的實作類型,新增至指定的 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

要新增的服務類型。

TImplementation

要使用的實作類型。

參數

services
IServiceCollection

要新增服務的 IServiceCollection

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

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

來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs

使用 implementationFactory 中指定的 Factory,將 TService 中指定類型的單一服務,以及 TImplementation 中指定的實作類型,新增至指定的 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

要新增的服務類型。

TImplementation

要使用的實作類型。

參數

services
IServiceCollection

要新增服務的 IServiceCollection

implementationFactory
Func<IServiceProvider,TImplementation>

建立服務的 Factory。

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

AddSingleton<TService>(IServiceCollection)

來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs

TService 中指定類型的單一服務,新增至指定的 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

要新增的服務類型。

參數

services
IServiceCollection

要新增服務的 IServiceCollection

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

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

來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs

TService 中指定類型的單一服務,以及 implementationFactory 中指定的 Factory,新增至指定的 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

要新增的服務類型。

參數

services
IServiceCollection

要新增服務的 IServiceCollection

implementationFactory
Func<IServiceProvider,TService>

建立服務的 Factory。

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於

AddSingleton<TService>(IServiceCollection, TService)

來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs
來源:
ServiceCollectionServiceExtensions.cs

TService 中指定類型的單一服務,以及 implementationInstance 中指定的執行個體,新增至指定的 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

要新增服務的 IServiceCollection

implementationInstance
TService

服務的執行個體。

傳回

完成作業之後,這個執行個體的參考。

另請參閱

適用於