ServiceCollectionMap.TryAddScoped 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
| 名稱 | Description |
|---|---|
| TryAddScoped(Type, Func<IServiceProvider,Object>) |
若該工廠尚未註冊該服務類型,則新增 Scoped 該工廠實作的服務。 |
| TryAddScoped(Type, Type) |
若尚未註冊該具體類型的服務,則新增 Scoped 由該具體類型實作的服務。 |
| TryAddScoped<TService,TImplementation>() |
若尚未註冊該具體類型的服務,則新增 Scoped 由該具體類型實作的服務。 |
| TryAddScoped<TService,TImplementation>(Func<IServiceProvider,TImplementation>) |
若該工廠尚未註冊該服務類型,則新增 Scoped 該工廠實作的服務。 |
| TryAddScoped<TService>(Func<IServiceProvider,TService>) |
若該工廠尚未註冊該服務類型,則新增 Scoped 該工廠實作的服務。 |
TryAddScoped(Type, Func<IServiceProvider,Object>)
若該工廠尚未註冊該服務類型,則新增 Scoped 該工廠實作的服務。
public virtual Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap TryAddScoped(Type serviceType, Func<IServiceProvider,object> factory);
abstract member TryAddScoped : Type * Func<IServiceProvider, obj> -> Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap
override this.TryAddScoped : Type * Func<IServiceProvider, obj> -> Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap
Public Overridable Function TryAddScoped (serviceType As Type, factory As Func(Of IServiceProvider, Object)) As ServiceCollectionMap
參數
- serviceType
- Type
服務合約。
- factory
- Func<IServiceProvider,Object>
實作這項服務的工廠。
傳回
映射,使得後續呼叫可以串連起來。
適用於
TryAddScoped(Type, Type)
若尚未註冊該具體類型的服務,則新增 Scoped 由該具體類型實作的服務。
public virtual Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap TryAddScoped(Type serviceType, Type implementationType);
abstract member TryAddScoped : Type * Type -> Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap
override this.TryAddScoped : Type * Type -> Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap
Public Overridable Function TryAddScoped (serviceType As Type, implementationType As Type) As ServiceCollectionMap
參數
- serviceType
- Type
服務合約。
- implementationType
- Type
就是實作服務的具體類型。
傳回
映射,使得後續呼叫可以串連起來。
適用於
TryAddScoped<TService,TImplementation>()
若尚未註冊該具體類型的服務,則新增 Scoped 由該具體類型實作的服務。
public virtual Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap TryAddScoped<TService,TImplementation>() where TService : class where TImplementation : class, TService;
abstract member TryAddScoped : unit -> Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap (requires 'Service : null)
override this.TryAddScoped : unit -> Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap (requires 'Service : null)
Public Overridable Function TryAddScoped(Of TService As Class, TImplementation As Class) () As ServiceCollectionMap
類型參數
- TService
服務合約。
- TImplementation
就是實作服務的具體類型。
傳回
映射,使得後續呼叫可以串連起來。
適用於
TryAddScoped<TService,TImplementation>(Func<IServiceProvider,TImplementation>)
若該工廠尚未註冊該服務類型,則新增 Scoped 該工廠實作的服務。
public virtual Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap TryAddScoped<TService,TImplementation>(Func<IServiceProvider,TImplementation> factory) where TService : class where TImplementation : class, TService;
abstract member TryAddScoped : Func<IServiceProvider, #'Service> -> Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap (requires 'Service : null)
override this.TryAddScoped : Func<IServiceProvider, #'Service> -> Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap (requires 'Service : null)
Public Overridable Function TryAddScoped(Of TService As Class, TImplementation As Class) (factory As Func(Of IServiceProvider, TImplementation)) As ServiceCollectionMap
類型參數
- TService
服務合約。
- TImplementation
就是該工廠所製造的混凝土類型。
參數
- factory
- Func<IServiceProvider,TImplementation>
實作這項服務的工廠。
傳回
映射,使得後續呼叫可以串連起來。
適用於
TryAddScoped<TService>(Func<IServiceProvider,TService>)
若該工廠尚未註冊該服務類型,則新增 Scoped 該工廠實作的服務。
public virtual Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap TryAddScoped<TService>(Func<IServiceProvider,TService> factory) where TService : class;
abstract member TryAddScoped : Func<IServiceProvider, 'Service (requires 'Service : null)> -> Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap (requires 'Service : null)
override this.TryAddScoped : Func<IServiceProvider, 'Service (requires 'Service : null)> -> Microsoft.EntityFrameworkCore.Infrastructure.ServiceCollectionMap (requires 'Service : null)
Public Overridable Function TryAddScoped(Of TService As Class) (factory As Func(Of IServiceProvider, TService)) As ServiceCollectionMap
類型參數
- TService
服務合約。
參數
- factory
- Func<IServiceProvider,TService>
實作這項服務的工廠。
傳回
映射,使得後續呼叫可以串連起來。