EntityFrameworkServiceCollectionExtensions.ConfigureDbContext メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
オーバーロード
ConfigureDbContext<TContext>(IServiceCollection, Action<IServiceProvider,DbContextOptionsBuilder>, ServiceLifetime)
IServiceCollectionで指定されたコンテキストの種類を構成します。
public static Microsoft.Extensions.DependencyInjection.IServiceCollection ConfigureDbContext<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<IServiceProvider,Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> optionsAction, Microsoft.Extensions.DependencyInjection.ServiceLifetime optionsLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member ConfigureDbContext : Microsoft.Extensions.DependencyInjection.IServiceCollection * Action<IServiceProvider, Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> * Microsoft.Extensions.DependencyInjection.ServiceLifetime -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function ConfigureDbContext(Of TContext As DbContext) (serviceCollection As IServiceCollection, optionsAction As Action(Of IServiceProvider, DbContextOptionsBuilder), Optional optionsLifetime As ServiceLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton) As IServiceCollection
型パラメーター
- TContext
登録するコンテキストの種類。
パラメーター
- serviceCollection
- IServiceCollection
サービスを追加する IServiceCollection 。
- optionsAction
- Action<IServiceProvider,DbContextOptionsBuilder>
コンテキストの DbContextOptions を構成するアクション。
- optionsLifetime
- ServiceLifetime
DbContextOptions サービスがコンテナーに登録される有効期間。
戻り値
複数の呼び出しをチェーンできるように、同じサービス コレクション。
注釈
AddDbContext<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime, ServiceLifetime)、 AddDbContextPool<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, Int32)、 AddDbContextFactory<TContext,TFactory>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime) 、または AddPooledDbContextFactory<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, Int32) も呼び出して、指定した構成を有効にする必要があります。 上記のいずれかの後にこのメソッドを呼び出すと、競合する構成が発生します。 プールされていないコンテキストの場合 OnConfiguring(DbContextOptionsBuilder) 構成は、ここで実行される構成に加えて適用されます。
このメソッドは複数回呼び出すことができます。構成は指定された順序で適用されます。
詳細と例については、 依存関係の挿入での DbContext の使用 を参照してください。
適用対象
ConfigureDbContext<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime)
IServiceCollectionで指定されたコンテキストの種類を構成します。
public static Microsoft.Extensions.DependencyInjection.IServiceCollection ConfigureDbContext<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> optionsAction, Microsoft.Extensions.DependencyInjection.ServiceLifetime optionsLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member ConfigureDbContext : Microsoft.Extensions.DependencyInjection.IServiceCollection * Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> * Microsoft.Extensions.DependencyInjection.ServiceLifetime -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function ConfigureDbContext(Of TContext As DbContext) (serviceCollection As IServiceCollection, optionsAction As Action(Of DbContextOptionsBuilder), Optional optionsLifetime As ServiceLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton) As IServiceCollection
型パラメーター
- TContext
登録するコンテキストの種類。
パラメーター
- serviceCollection
- IServiceCollection
サービスを追加する IServiceCollection 。
- optionsAction
- Action<DbContextOptionsBuilder>
コンテキストの DbContextOptions を構成するアクション。
- optionsLifetime
- ServiceLifetime
DbContextOptions サービスがコンテナーに登録される有効期間。
戻り値
複数の呼び出しをチェーンできるように、同じサービス コレクション。
注釈
AddDbContext<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime, ServiceLifetime)、 AddDbContextPool<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, Int32)、 AddDbContextFactory<TContext,TFactory>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime) 、または AddPooledDbContextFactory<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, Int32) も呼び出して、指定した構成を有効にする必要があります。 上記のいずれかの後にこのメソッドを呼び出すと、競合する構成が発生します。 プールされていないコンテキストの場合 OnConfiguring(DbContextOptionsBuilder) 構成は、ここで実行される構成に加えて適用されます。
このメソッドは複数回呼び出すことができます。構成は指定された順序で適用されます。
詳細と例については、 依存関係の挿入での DbContext の使用 を参照してください。