ServiceCollectionDescriptorExtensions.TryAddScoped 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
TryAddScoped(IServiceCollection, Type) |
如果尚未註冊服務類型,則將指定的 |
TryAddScoped(IServiceCollection, Type, Func<IServiceProvider,Object>) |
如果尚未註冊服務類型,則使用 |
TryAddScoped(IServiceCollection, Type, Type) |
如果尚未註冊服務類型,則將所指定 |
TryAddScoped<TService,TImplementation>(IServiceCollection) |
如果尚未註冊服務類型,則將指定 |
TryAddScoped<TService>(IServiceCollection) |
如果尚未註冊服務類型,則將指定的 |
TryAddScoped<TService>(IServiceCollection, Func<IServiceProvider,TService>) |
如果尚未註冊服務類型,則使用 |
TryAddScoped(IServiceCollection, Type)
如果尚未註冊服務類型,則將指定的 service
作為 Scoped 服務新增至 collection
。
public:
[System::Runtime::CompilerServices::Extension]
static void TryAddScoped(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ collection, Type ^ service);
public static void TryAddScoped (this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Type service);
static member TryAddScoped : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type -> unit
<Extension()>
Public Sub TryAddScoped (collection As IServiceCollection, service As Type)
參數
- collection
- IServiceCollection
- service
- Type
要註冊的服務類型。
適用於
TryAddScoped(IServiceCollection, Type, Func<IServiceProvider,Object>)
如果尚未註冊服務類型,則使用 implementationFactory
中指定的 Factory,將指定的 service
作為 Scoped 服務新增至 collection
。
public:
[System::Runtime::CompilerServices::Extension]
static void TryAddScoped(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ collection, Type ^ service, Func<IServiceProvider ^, System::Object ^> ^ implementationFactory);
public static void TryAddScoped (this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Type service, Func<IServiceProvider,object> implementationFactory);
static member TryAddScoped : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * Func<IServiceProvider, obj> -> unit
<Extension()>
Public Sub TryAddScoped (collection As IServiceCollection, service As Type, implementationFactory As Func(Of IServiceProvider, Object))
參數
- collection
- IServiceCollection
- service
- Type
要註冊的服務類型。
- implementationFactory
- Func<IServiceProvider,Object>
建立服務的 Factory。
適用於
TryAddScoped(IServiceCollection, Type, Type)
如果尚未註冊服務類型,則將所指定 service
作為具有 implementationType
的 Scoped 服務新增至 collection
。
public:
[System::Runtime::CompilerServices::Extension]
static void TryAddScoped(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ collection, Type ^ service, Type ^ implementationType);
public static void TryAddScoped (this Microsoft.Extensions.DependencyInjection.IServiceCollection collection, Type service, Type implementationType);
static member TryAddScoped : Microsoft.Extensions.DependencyInjection.IServiceCollection * Type * Type -> unit
<Extension()>
Public Sub TryAddScoped (collection As IServiceCollection, service As Type, implementationType As Type)
參數
- collection
- IServiceCollection
- service
- Type
要註冊的服務類型。
- implementationType
- Type
服務的實作類型。
適用於
TryAddScoped<TService,TImplementation>(IServiceCollection)
如果尚未註冊服務類型,則將指定 TService
作為 TImplementation
中指定的 Scoped 服務實作類型新增至 collection
。
public:
generic <typename TService, typename TImplementation>
where TService : class where TImplementation : class, TService[System::Runtime::CompilerServices::Extension]
static void TryAddScoped(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ collection);
public static void TryAddScoped<TService,TImplementation> (this Microsoft.Extensions.DependencyInjection.IServiceCollection collection) where TService : class where TImplementation : class, TService;
static member TryAddScoped : Microsoft.Extensions.DependencyInjection.IServiceCollection -> unit (requires 'Service : null)
<Extension()>
Public Sub TryAddScoped(Of TService As Class, TImplementation As Class) (collection As IServiceCollection)
類型參數
- TService
要新增的服務類型。
- TImplementation
要使用的實作類型。
參數
- collection
- IServiceCollection
適用於
TryAddScoped<TService>(IServiceCollection)
如果尚未註冊服務類型,則將指定的 TService
作為 Scoped 服務新增至 collection
。
public:
generic <typename TService>
where TService : class[System::Runtime::CompilerServices::Extension]
static void TryAddScoped(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ collection);
public static void TryAddScoped<TService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection collection) where TService : class;
static member TryAddScoped : Microsoft.Extensions.DependencyInjection.IServiceCollection -> unit (requires 'Service : null)
<Extension()>
Public Sub TryAddScoped(Of TService As Class) (collection As IServiceCollection)
類型參數
- TService
要新增的服務類型。
參數
- collection
- IServiceCollection
適用於
TryAddScoped<TService>(IServiceCollection, Func<IServiceProvider,TService>)
如果尚未註冊服務類型,則使用 implementationFactory
中指定的 Factory,將指定的 TService
作為 Scoped 服務新增至 services
。
public:
generic <typename TService>
where TService : class[System::Runtime::CompilerServices::Extension]
static void TryAddScoped(Microsoft::Extensions::DependencyInjection::IServiceCollection ^ services, Func<IServiceProvider ^, TService> ^ implementationFactory);
public static void TryAddScoped<TService> (this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Func<IServiceProvider,TService> implementationFactory) where TService : class;
static member TryAddScoped : Microsoft.Extensions.DependencyInjection.IServiceCollection * Func<IServiceProvider, 'Service (requires 'Service : null)> -> unit (requires 'Service : null)
<Extension()>
Public Sub TryAddScoped(Of TService As Class) (services As IServiceCollection, implementationFactory As Func(Of IServiceProvider, TService))
類型參數
- TService
要新增的服務類型。
參數
- services
- IServiceCollection
- implementationFactory
- Func<IServiceProvider,TService>
建立服務的 Factory。