語言

EntityFrameworkServicesBuilder 類別

定義

一個為資料庫提供者設計的建構 API,供註冊服務時使用。

public class EntityFrameworkServicesBuilder : Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<Microsoft.Extensions.DependencyInjection.IServiceCollection>
[System.Runtime.CompilerServices.Nullable(0)]
public class EntityFrameworkServicesBuilder
public class EntityFrameworkServicesBuilder
type EntityFrameworkServicesBuilder = class
    interface IInfrastructure<IServiceCollection>
[<System.Runtime.CompilerServices.Nullable(0)>]
type EntityFrameworkServicesBuilder = class
type EntityFrameworkServicesBuilder = class
Public Class EntityFrameworkServicesBuilder
Implements IInfrastructure(Of IServiceCollection)
Public Class EntityFrameworkServicesBuilder
繼承
EntityFrameworkServicesBuilder
衍生
屬性
實作

備註

提供者應建立此類別的實例,利用其方法註冊服務,然後呼叫 TryAddCoreServices() 以填寫剩餘的實體框架服務。

關聯型服務提供者應該改用「EntityFrameworkRelationalServicesBuilder」。

實體框架確保服務以適當的範圍註冊。 在某些情況下,提供者可能會註冊使用不同範圍的服務,但必須非常謹慎,確保所有相依性能處理新範圍,且不會對依賴該範圍的服務造成問題。

更多資訊與範例請參見 資料庫提供者與擴充功能的實作 。

建構函式

名稱 Description
EntityFrameworkServicesBuilder(IServiceCollection)

資料庫提供者用於建立新的 EntityFrameworkServicesBuilder 服務提供者註冊資料。 關聯性提供者應使用「EntityFrameworkRelationalServicesBuilder」。

欄位

名稱 Description
CoreServices

這是一個內部 API,支援 Entity Framework Core 基礎架構,且不受公開 API 相同的相容性標準約束。 該內容可能會在任何新聞稿中未經通知而更改或移除。 你應該只在程式碼中直接使用它,並且要非常謹慎,並且要知道這樣做可能會導致更新到新的 Entity Framework Core 版本時應用程式失敗。

屬性

名稱 Description
ServiceCollectionMap

存取底層 ServiceCollectionMap。

方法

名稱 Description
GetServiceCharacteristics(Type)

會針對特定服務類型取得 。ServiceCharacteristics

TryAdd(Type, Object)

僅在尚未註冊實體框架服務時,才會新增實作。 此方法僅可用於單例服務。

TryAdd(Type, Type, Func<IServiceProvider,Object>)

只有在尚未註冊的 Entity Framework 服務工廠時,才會新增工廠。 服務範圍由 Entity Framework 自動定義。

TryAdd(Type, Type)

僅在尚未註冊實體框架服務時,才會新增實作。 服務範圍由 Entity Framework 自動定義。

TryAdd<TService,TImplementation>()

僅在尚未註冊實體框架服務時,才會新增實作。 服務範圍由 Entity Framework 自動定義。

TryAdd<TService,TImplementation>(Func<IServiceProvider,TImplementation>)

只有在尚未註冊的 Entity Framework 服務工廠時,才會新增工廠。 服務範圍由 Entity Framework 自動定義。

TryAdd<TService>(Func<IServiceProvider,TService>)

只有在尚未註冊的 Entity Framework 服務工廠時,才會新增工廠。 服務範圍由 Entity Framework 自動定義。

TryAdd<TService>(TService)

僅在尚未註冊實體框架服務時,才會新增實作。 此方法僅可用於單例服務。

TryAddCoreServices()

登錄所有尚未由提供者註冊的服務的預設實作。 資料庫提供者必須將此方法視為服務註冊的最後一步——也就是在所有提供者服務註冊完成後。

TryAddProviderSpecificServices(Action<ServiceCollectionMap>)

資料庫提供者應呼叫此方法以存取底層 ServiceCollectionMap ,以便註冊提供者專屬服務。 請注意,實體框架服務的實作應直接註冊於 Entity EntityFrameworkServicesBuilder Deck,而非透過此方法。

TryGetServiceCharacteristics(Type)

會針對特定服務類型取得 。ServiceCharacteristics

明確介面實作

名稱 Description
IInfrastructure<IServiceCollection>.Instance

能設定 IServiceCollection 好被設定。

此特性是為需要利用未直接暴露於公開 API 表面服務的擴充方法所設計。

擴充方法

名稱 Description
GetInfrastructure<T>(IInfrastructure<T>)

從一個被隱藏的屬性中取得價值 IInfrastructure<T>。

此方法通常由資料庫提供者(及其他擴充)使用。 它通常不被用於應用程式程式碼中。

適用於