Language

EntityFrameworkServiceCollectionExtensions.AddPooledDbContextFactory メソッド

定義

オーバーロード

Name 説明
AddPooledDbContextFactory<TContext>(IServiceCollection, Int32)

カスタム プール サイズを使用して、指定したDbContextの種類のインスタンスを作成するためのプールされたIDbContextFactory<TContext>をIServiceCollectionに登録します。

AddPooledDbContextFactory<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, Int32)

IServiceCollectionにIDbContextFactory<TContext>を登録して、インスタンスが再利用のためにプールされる特定のDbContext型のインスタンスを作成します。

AddPooledDbContextFactory<TContext>(IServiceCollection, Action<IServiceProvider,DbContextOptionsBuilder>, Int32)

IServiceCollectionにIDbContextFactory<TContext>を登録して、インスタンスが再利用のためにプールされる特定のDbContext型のインスタンスを作成します。

AddPooledDbContextFactory<TContext>(IServiceCollection, Int32)

ソース:
EntityFrameworkServiceCollectionExtensions.cs

カスタム プール サイズを使用して、指定したDbContextの種類のインスタンスを作成するためのプールされたIDbContextFactory<TContext>をIServiceCollectionに登録します。

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddPooledDbContextFactory<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, int poolSize = 1024) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member AddPooledDbContextFactory : Microsoft.Extensions.DependencyInjection.IServiceCollection * int -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function AddPooledDbContextFactory(Of TContext As DbContext) (serviceCollection As IServiceCollection, Optional poolSize As Integer = 1024) As IServiceCollection

型パラメーター

TContext

ファクトリによって作成される DbContext の種類。

パラメーター

serviceCollection
IServiceCollection

サービスが追加される IServiceCollection 。

poolSize
Int32

プールによって保持される TContext インスタンスの最大数。 既定値は 1024 です。

戻り値

複数の呼び出しをチェーンできるように、同じ IServiceCollection 。

注釈

このオーバーロードは、EF Core 集中型構成モデルの ConfigureDbContext<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime)に合わせて調整されます。 カスタム poolSizeを指定できます。 ConfigureDbContext<TContext>を使用して構成されたオプションは自動的に使用されるため、プロバイダーの構成を繰り返す必要がなくなります。

ASP.NET Coreなど、アプリケーションで依存関係の挿入を使用する場合は、このメソッドを使用します。 依存関係の挿入を使用しないアプリケーションの場合は、コンストラクターを使用して DbContext インスタンスを直接作成することを検討してください。 その後、OnConfiguring(DbContextOptionsBuilder) メソッドをオーバーライドして、接続文字列やその他のオプションを構成できます。

Entity Framework Core では、同じ DbContext インスタンス上での複数の並列操作の実行がサポートされていません。 これには、非同期クエリの並列実行と、複数のスレッドからの明示的な同時使用の両方が含まれます。 したがって、常に非同期呼び出しをすぐに待機するか、並列で実行される操作に個別の DbContext インスタンスを使用します。 詳細と例については、 DbContext スレッドの問題の回避に 関するページを参照してください。

詳細と例については、 依存関係の挿入での DbContext の 使用、DbContext ファクトリの使用、 および DbContext プールの使用 を参照してください。

適用対象

AddPooledDbContextFactory<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, Int32)

ソース:
EntityFrameworkServiceCollectionExtensions.cs
ソース:
EntityFrameworkServiceCollectionExtensions.cs
ソース:
EntityFrameworkServiceCollectionExtensions.cs
ソース:
EntityFrameworkServiceCollectionExtensions.cs
ソース:
EntityFrameworkServiceCollectionExtensions.cs
ソース:
EntityFrameworkServiceCollectionExtensions.cs
ソース:
EntityFrameworkServiceCollectionExtensions.cs

IServiceCollectionにIDbContextFactory<TContext>を登録して、インスタンスが再利用のためにプールされる特定のDbContext型のインスタンスを作成します。

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddPooledDbContextFactory<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> optionsAction, int poolSize = 1024) where TContext : Microsoft.EntityFrameworkCore.DbContext;
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddPooledDbContextFactory<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> optionsAction, int poolSize = 128) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member AddPooledDbContextFactory : Microsoft.Extensions.DependencyInjection.IServiceCollection * Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> * int -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function AddPooledDbContextFactory(Of TContext As DbContext) (serviceCollection As IServiceCollection, optionsAction As Action(Of DbContextOptionsBuilder), Optional poolSize As Integer = 1024) As IServiceCollection
<Extension()>
Public Function AddPooledDbContextFactory(Of TContext As DbContext) (serviceCollection As IServiceCollection, optionsAction As Action(Of DbContextOptionsBuilder), Optional poolSize As Integer = 128) As IServiceCollection

型パラメーター

TContext

ファクトリによって作成される DbContext の種類。

パラメーター

serviceCollection
IServiceCollection

サービスを追加する IServiceCollection 。

optionsAction
Action<DbContextOptionsBuilder>

コンテキストの DbContextOptions を構成するために必要なアクション。 コンテキスト プールを使用する場合は、オプションの構成を外部で実行する必要があります。 OnConfiguring(DbContextOptionsBuilder) は呼び出されません。

poolSize
Int32

プールによって保持されるインスタンスの最大数を設定します。 既定値は 1024 です。

戻り値

複数の呼び出しをチェーンできるように、同じサービス コレクション。

注釈

コンテキスト型を直接登録する代わりにファクトリを登録すると、新しい DbContext インスタンスを簡単に作成できます。 Blazor アプリケーションやその他の状況で依存関係の挿入スコープがコンテキストの有効期間と一致しない場合は、ファクトリの登録をお勧めします。

Blazor など、アプリケーションで依存関係の挿入を使用する場合は、このメソッドを使用します。 依存関係の挿入を使用しないアプリケーションの場合は、コンストラクターを使用して DbContext インスタンスを直接作成することを検討してください。 その後、OnConfiguring(DbContextOptionsBuilder) メソッドをオーバーライドして、接続文字列やその他のオプションを構成できます。

Entity Framework Core では、同じ DbContext インスタンス上での複数の並列操作の実行がサポートされていません。 これには、非同期クエリの並列実行と、複数のスレッドからの明示的な同時使用の両方が含まれます。 したがって、常に非同期呼び出しをすぐに待機するか、並列で実行される操作に個別の DbContext インスタンスを使用します。 詳細と例については、 DbContext スレッドの問題の回避に 関するページを参照してください。

詳細と例については、 依存関係の挿入での DbContext の 使用、DbContext ファクトリの使用、 および DbContext プールの使用 を参照してください。

適用対象

AddPooledDbContextFactory<TContext>(IServiceCollection, Action<IServiceProvider,DbContextOptionsBuilder>, Int32)

ソース:
EntityFrameworkServiceCollectionExtensions.cs
ソース:
EntityFrameworkServiceCollectionExtensions.cs
ソース:
EntityFrameworkServiceCollectionExtensions.cs
ソース:
EntityFrameworkServiceCollectionExtensions.cs
ソース:
EntityFrameworkServiceCollectionExtensions.cs
ソース:
EntityFrameworkServiceCollectionExtensions.cs
ソース:
EntityFrameworkServiceCollectionExtensions.cs

IServiceCollectionにIDbContextFactory<TContext>を登録して、インスタンスが再利用のためにプールされる特定のDbContext型のインスタンスを作成します。

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddPooledDbContextFactory<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<IServiceProvider,Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> optionsAction, int poolSize = 1024) where TContext : Microsoft.EntityFrameworkCore.DbContext;
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddPooledDbContextFactory<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<IServiceProvider,Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> optionsAction, int poolSize = 128) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member AddPooledDbContextFactory : Microsoft.Extensions.DependencyInjection.IServiceCollection * Action<IServiceProvider, Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> * int -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function AddPooledDbContextFactory(Of TContext As DbContext) (serviceCollection As IServiceCollection, optionsAction As Action(Of IServiceProvider, DbContextOptionsBuilder), Optional poolSize As Integer = 1024) As IServiceCollection
<Extension()>
Public Function AddPooledDbContextFactory(Of TContext As DbContext) (serviceCollection As IServiceCollection, optionsAction As Action(Of IServiceProvider, DbContextOptionsBuilder), Optional poolSize As Integer = 128) As IServiceCollection

型パラメーター

TContext

ファクトリによって作成される DbContext の種類。

パラメーター

serviceCollection
IServiceCollection

サービスを追加する IServiceCollection 。

optionsAction
Action<IServiceProvider,DbContextOptionsBuilder>

コンテキストの DbContextOptions を構成するために必要なアクション。 コンテキスト プールを使用する場合は、オプションの構成を外部で実行する必要があります。 OnConfiguring(DbContextOptionsBuilder) は呼び出されません。

poolSize
Int32

プールによって保持されるインスタンスの最大数を設定します。 既定値は 1024 です。

戻り値

複数の呼び出しをチェーンできるように、同じサービス コレクション。

注釈

コンテキスト型を直接登録する代わりにファクトリを登録すると、新しい DbContext インスタンスを簡単に作成できます。 Blazor アプリケーションやその他の状況で依存関係の挿入スコープがコンテキストの有効期間と一致しない場合は、ファクトリの登録をお勧めします。

Blazor など、アプリケーションで依存関係の挿入を使用する場合は、このメソッドを使用します。 依存関係の挿入を使用しないアプリケーションの場合は、コンストラクターを使用して DbContext インスタンスを直接作成することを検討してください。 その後、OnConfiguring(DbContextOptionsBuilder) メソッドをオーバーライドして、接続文字列やその他のオプションを構成できます。

Entity Framework Core では、同じ DbContext インスタンス上での複数の並列操作の実行がサポートされていません。 これには、非同期クエリの並列実行と、複数のスレッドからの明示的な同時使用の両方が含まれます。 したがって、常に非同期呼び出しをすぐに待機するか、並列で実行される操作に個別の DbContext インスタンスを使用します。 詳細と例については、 DbContext スレッドの問題の回避に 関するページを参照してください。

詳細と例については、 依存関係の挿入での DbContext の 使用、DbContext ファクトリの使用、 および DbContext プールの使用 を参照してください。

適用対象