DbContextOptionsBuilder.ReplaceService 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
| 名稱 | Description |
|---|---|
| ReplaceService<TService,TCurrentImplementation,TNewImplementation>() |
以不同的實作取代特定服務合約的內部實體框架實作。 |
| ReplaceService<TService,TImplementation>() |
以不同的實作替換所有內部實體框架的服務合約實作。 |
ReplaceService<TService,TCurrentImplementation,TNewImplementation>()
以不同的實作取代特定服務合約的內部實體框架實作。
public virtual Microsoft.EntityFrameworkCore.DbContextOptionsBuilder ReplaceService<TService,TCurrentImplementation,TNewImplementation>() where TCurrentImplementation : TService where TNewImplementation : TService;
abstract member ReplaceService : unit -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
override this.ReplaceService : unit -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
Public Overridable Function ReplaceService(Of TService, TCurrentImplementation, TNewImplementation) () As DbContextOptionsBuilder
類型參數
- TService
定義服務要替換的合約的類型(通常是介面)。
- TCurrentImplementation
目前服務的實作類型。
- TNewImplementation
服務的新實作類型。
傳回
同一個建構實例,這樣可以串接多個呼叫。
備註
此方法有助於替換可在 EF 內部服務提供者中合法註冊多次的單一服務實例。
此方法僅適用於 EF 建置並管理其內部服務提供者時。 如果服務提供者是外部建置並傳入 UseInternalServiceProvider(IServiceProvider),則應先在該服務提供者上設定替代服務,然後再傳給 EF。
替換服務的範圍與它所取代的EF服務相同。
更多資訊與範例請參見 使用 DbContextOptions 。
適用於
ReplaceService<TService,TImplementation>()
以不同的實作替換所有內部實體框架的服務合約實作。
public virtual Microsoft.EntityFrameworkCore.DbContextOptionsBuilder ReplaceService<TService,TImplementation>() where TImplementation : TService;
abstract member ReplaceService : unit -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
override this.ReplaceService : unit -> Microsoft.EntityFrameworkCore.DbContextOptionsBuilder
Public Overridable Function ReplaceService(Of TService, TImplementation) () As DbContextOptionsBuilder
類型參數
- TService
定義服務要替換的合約的類型(通常是介面)。
- TImplementation
服務的新實作類型。
傳回
同一個建構實例,這樣可以串接多個呼叫。
備註
此方法僅適用於 EF 建置並管理其內部服務提供者時。 如果服務提供者是外部建置並傳入 UseInternalServiceProvider(IServiceProvider),則應先在該服務提供者上設定替代服務,然後再傳給 EF。
替換服務的範圍與它所取代的EF服務相同。
更多資訊與範例請參見 使用 DbContextOptions 。