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