Dil

EntityFrameworkServiceCollectionExtensions.AddDbContext Yöntem

Tanım

Aşırı Yüklemeler

Veri Akışı Adı Description
AddDbContext<TContext>(IServiceCollection, ServiceLifetime)

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder. Bu yöntemi, ASP.NET gibi uygulamanızda bağımlılık ekleme özelliğini kullanırken kullanırsınız. Bağımlılık eklemeyi ayarlama hakkında daha fazla bilgi için bkz http://go.microsoft.com/fwlink/?LinkId=526890. .

AddDbContext<TContext>(IServiceCollection, ServiceLifetime, ServiceLifetime)

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder.

AddDbContext<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime)

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder. Bu yöntemi, ASP.NET gibi uygulamanızda bağımlılık ekleme özelliğini kullanırken kullanırsınız. Bağımlılık eklemeyi ayarlama hakkında daha fazla bilgi için bkz http://go.microsoft.com/fwlink/?LinkId=526890. .

AddDbContext<TContext>(IServiceCollection, Action<IServiceProvider,DbContextOptionsBuilder>, ServiceLifetime)

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder. Bu yöntemi, ASP.NET gibi uygulamanızda bağımlılık ekleme özelliğini kullanırken kullanırsınız. Bağımlılık eklemeyi ayarlama hakkında daha fazla bilgi için bkz. http://go.microsoft.com/fwlink/?LinkId=526890.

Bu aşırı yükleme, uygulamaları IServiceProvidersağlayan bir optionsAction öğesine sahiptir. Birincil uygulama hizmeti sağlayıcısından gelen iç hizmetlerini çözümlemek için Entity Framework'ün ayarlanmasını istiyorsanız bu yararlı olur. Varsayılan olarak, Entity Framework'ün iç Entity Framework hizmetleri için kendi IServiceProvider yükünü oluşturmasını ve korumasını sağlayan diğer aşırı yüklemeyi kullanmanızı öneririz.

AddDbContext<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime, ServiceLifetime)

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder.

AddDbContext<TContext>(IServiceCollection, Action<IServiceProvider,DbContextOptionsBuilder>, ServiceLifetime, ServiceLifetime)

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder.

AddDbContext<TContextService,TContextImplementation>(IServiceCollection, ServiceLifetime, ServiceLifetime)

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder.

AddDbContext<TContextService,TContextImplementation>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime, ServiceLifetime)

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder.

AddDbContext<TContextService,TContextImplementation>(IServiceCollection, Action<IServiceProvider,DbContextOptionsBuilder>, ServiceLifetime, ServiceLifetime)

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder.

AddDbContext<TContext>(IServiceCollection, ServiceLifetime)

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder. Bu yöntemi, ASP.NET gibi uygulamanızda bağımlılık ekleme özelliğini kullanırken kullanırsınız. Bağımlılık eklemeyi ayarlama hakkında daha fazla bilgi için bkz http://go.microsoft.com/fwlink/?LinkId=526890. .

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDbContext<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Microsoft.Extensions.DependencyInjection.ServiceLifetime contextLifetime) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member AddDbContext : Microsoft.Extensions.DependencyInjection.IServiceCollection * Microsoft.Extensions.DependencyInjection.ServiceLifetime -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function AddDbContext(Of TContext As DbContext) (serviceCollection As IServiceCollection, contextLifetime As ServiceLifetime) As IServiceCollection

Tür Parametreleri

TContext

Kaydedilecek bağlam türü.

Parametreler

serviceCollection
IServiceCollection

IServiceCollection için hizmetler eklenir.

contextLifetime
ServiceLifetime

DbContext hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

Döndürülenler

Birden çok çağrının zincirlenebilmesi için aynı hizmet koleksiyonu.

Örnekler

public void ConfigureServices(IServiceCollection services) 
{
    var connectionString = "connection string to database";

    services.AddDbContext<MyContext>(ServiceLifetime.Scoped); 
}

Şunlara uygulanır

AddDbContext<TContext>(IServiceCollection, ServiceLifetime, ServiceLifetime)

Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder.

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDbContext<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Microsoft.Extensions.DependencyInjection.ServiceLifetime contextLifetime, Microsoft.Extensions.DependencyInjection.ServiceLifetime optionsLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member AddDbContext : Microsoft.Extensions.DependencyInjection.IServiceCollection * Microsoft.Extensions.DependencyInjection.ServiceLifetime * Microsoft.Extensions.DependencyInjection.ServiceLifetime -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function AddDbContext(Of TContext As DbContext) (serviceCollection As IServiceCollection, contextLifetime As ServiceLifetime, Optional optionsLifetime As ServiceLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) As IServiceCollection

Tür Parametreleri

TContext

Kaydedilecek bağlam türü.

Parametreler

serviceCollection
IServiceCollection

IServiceCollection için hizmetler eklenir.

contextLifetime
ServiceLifetime

DbContext hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

optionsLifetime
ServiceLifetime

DbContextOptions hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

Döndürülenler

Birden çok çağrının zincirlenebilmesi için aynı hizmet koleksiyonu.

Örnekler

public void ConfigureServices(IServiceCollection services)
{
    var connectionString = "connection string to database";

    services.AddDbContext<MyContext>(ServiceLifetime.Scoped);
}

Açıklamalar

ASP.NET Core gibi uygulamanızda bağımlılık ekleme özelliğini kullanırken bu yöntemi kullanın. Bağımlılık ekleme kullanmayan uygulamalar için doğrudan oluşturucuyla örnek oluşturmayı DbContext göz önünde bulundurun. Daha OnConfiguring(DbContextOptionsBuilder) sonra bir bağlantı dizesi ve diğer seçenekleri yapılandırmak için yöntemi geçersiz kılınabilir.

Entity Framework Core, aynı DbContext örneğinde birden çok paralel işlemin çalıştırılmasını desteklemez. Buna hem zaman uyumsuz sorguların paralel yürütülmesi hem de birden çok iş parçacığından açık eş zamanlı kullanım dahildir. Bu nedenle, her zaman zaman uyumsuz çağrıları hemen bekleyin veya paralel olarak yürütülen işlemler için ayrı DbContext örnekleri kullanın. Daha fazla bilgi ve örnek için bkz. DbContext iş parçacığı oluşturma sorunlarını önleme .

Daha fazla bilgi ve örnek için bkz. DbContext'i bağımlılık ekleme ile kullanma .

Şunlara uygulanır

AddDbContext<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime)

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder. Bu yöntemi, ASP.NET gibi uygulamanızda bağımlılık ekleme özelliğini kullanırken kullanırsınız. Bağımlılık eklemeyi ayarlama hakkında daha fazla bilgi için bkz http://go.microsoft.com/fwlink/?LinkId=526890. .

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDbContext<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> optionsAction = default, Microsoft.Extensions.DependencyInjection.ServiceLifetime contextLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member AddDbContext : Microsoft.Extensions.DependencyInjection.IServiceCollection * Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> * Microsoft.Extensions.DependencyInjection.ServiceLifetime -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function AddDbContext(Of TContext As DbContext) (serviceCollection As IServiceCollection, Optional optionsAction As Action(Of DbContextOptionsBuilder) = Nothing, Optional contextLifetime As ServiceLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) As IServiceCollection

Tür Parametreleri

TContext

Kaydedilecek bağlam türü.

Parametreler

serviceCollection
IServiceCollection

IServiceCollection için hizmetler eklenir.

optionsAction
Action<DbContextOptionsBuilder>

bağlamını yapılandırmak DbContextOptions için isteğe bağlı bir eylemdir. Bu, türetilmiş bağlamınızdaki yöntemini geçersiz kılarak bağlam yapılandırmasını gerçekleştirmeye OnConfiguring(DbContextOptionsBuilder) bir alternatif sağlar.

Burada bir eylem sağlanırsa, OnConfiguring(DbContextOptionsBuilder) yöntem türetilmiş bağlamda geçersiz kılındıysa yine de çalıştırılır. OnConfiguring(DbContextOptionsBuilder) yapılandırma, burada gerçekleştirilen yapılandırmaya ek olarak uygulanır.

Seçeneklerin bağlamınıza geçirilebilmesi için, bağlamınız üzerinde bunu alıp DbContextOptions<TContext> temel oluşturucusuna geçiren bir oluşturucuyu DbContextkullanıma sunmanız gerekir.

contextLifetime
ServiceLifetime

DbContext hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

Döndürülenler

Birden çok çağrının zincirlenebilmesi için aynı hizmet koleksiyonu.

Örnekler

public void ConfigureServices(IServiceCollection services) 
{
    var connectionString = "connection string to database";

    services.AddDbContext<MyContext>(options => options.UseSqlServer(connectionString)); 
}

Şunlara uygulanır

AddDbContext<TContext>(IServiceCollection, Action<IServiceProvider,DbContextOptionsBuilder>, ServiceLifetime)

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder. Bu yöntemi, ASP.NET gibi uygulamanızda bağımlılık ekleme özelliğini kullanırken kullanırsınız. Bağımlılık eklemeyi ayarlama hakkında daha fazla bilgi için bkz. http://go.microsoft.com/fwlink/?LinkId=526890.

Bu aşırı yükleme, uygulamaları IServiceProvidersağlayan bir optionsAction öğesine sahiptir. Birincil uygulama hizmeti sağlayıcısından gelen iç hizmetlerini çözümlemek için Entity Framework'ün ayarlanmasını istiyorsanız bu yararlı olur. Varsayılan olarak, Entity Framework'ün iç Entity Framework hizmetleri için kendi IServiceProvider yükünü oluşturmasını ve korumasını sağlayan diğer aşırı yüklemeyi kullanmanızı öneririz.

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDbContext<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<IServiceProvider,Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> optionsAction, Microsoft.Extensions.DependencyInjection.ServiceLifetime contextLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member AddDbContext : 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 AddDbContext(Of TContext As DbContext) (serviceCollection As IServiceCollection, optionsAction As Action(Of IServiceProvider, DbContextOptionsBuilder), Optional contextLifetime As ServiceLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) As IServiceCollection

Tür Parametreleri

TContext

Kaydedilecek bağlam türü.

Parametreler

serviceCollection
IServiceCollection

IServiceCollection için hizmetler eklenir.

optionsAction
Action<IServiceProvider,DbContextOptionsBuilder>

bağlamını yapılandırmak DbContextOptions için isteğe bağlı bir eylemdir. Bu, türetilmiş bağlamınızdaki yöntemini geçersiz kılarak bağlam yapılandırmasını gerçekleştirmeye OnConfiguring(DbContextOptionsBuilder) bir alternatif sağlar.

Burada bir eylem sağlanırsa, OnConfiguring(DbContextOptionsBuilder) yöntem türetilmiş bağlamda geçersiz kılındıysa yine de çalıştırılır. OnConfiguring(DbContextOptionsBuilder) yapılandırma, burada gerçekleştirilen yapılandırmaya ek olarak uygulanır.

Seçeneklerin bağlamınıza geçirilebilmesi için, bağlamınız üzerinde bunu alıp DbContextOptions<TContext> temel oluşturucusuna geçiren bir oluşturucuyu DbContextkullanıma sunmanız gerekir.

contextLifetime
ServiceLifetime

DbContext hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

Döndürülenler

Birden çok çağrının zincirlenebilmesi için aynı hizmet koleksiyonu.

Örnekler

public void ConfigureServices(IServiceCollection services) 
{
    var connectionString = "connection string to database";

    services
        .AddEntityFrameworkSqlServer()
        .AddDbContext<MyContext>((serviceProvider, options) => 
            options.UseSqlServer(connectionString)
                   .UseInternalServiceProvider(serviceProvider)); 
}

Şunlara uygulanır

AddDbContext<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime, ServiceLifetime)

Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder.

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDbContext<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder>? optionsAction = default, Microsoft.Extensions.DependencyInjection.ServiceLifetime contextLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped, Microsoft.Extensions.DependencyInjection.ServiceLifetime optionsLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) where TContext : Microsoft.EntityFrameworkCore.DbContext;
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDbContext<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> optionsAction = default, Microsoft.Extensions.DependencyInjection.ServiceLifetime contextLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped, Microsoft.Extensions.DependencyInjection.ServiceLifetime optionsLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member AddDbContext : Microsoft.Extensions.DependencyInjection.IServiceCollection * Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> * Microsoft.Extensions.DependencyInjection.ServiceLifetime * Microsoft.Extensions.DependencyInjection.ServiceLifetime -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function AddDbContext(Of TContext As DbContext) (serviceCollection As IServiceCollection, Optional optionsAction As Action(Of DbContextOptionsBuilder) = Nothing, Optional contextLifetime As ServiceLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped, Optional optionsLifetime As ServiceLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) As IServiceCollection

Tür Parametreleri

TContext

Kaydedilecek bağlam türü.

Parametreler

serviceCollection
IServiceCollection

IServiceCollection için hizmetler eklenir.

optionsAction
Action<DbContextOptionsBuilder>

bağlamını yapılandırmak DbContextOptions için isteğe bağlı bir eylemdir. Bu, türetilmiş bağlamınızdaki yöntemini geçersiz kılarak bağlam yapılandırmasını gerçekleştirmeye OnConfiguring(DbContextOptionsBuilder) bir alternatif sağlar.

Burada bir eylem sağlanırsa, OnConfiguring(DbContextOptionsBuilder) yöntem türetilmiş bağlamda geçersiz kılındıysa yine de çalıştırılır. OnConfiguring(DbContextOptionsBuilder) yapılandırma, burada gerçekleştirilen yapılandırmaya ek olarak uygulanır.

Seçeneklerin bağlamınıza geçirilebilmesi için, bağlamınız üzerinde bunu alıp DbContextOptions<TContext> temel oluşturucusuna geçiren bir oluşturucuyu DbContextkullanıma sunmanız gerekir.

contextLifetime
ServiceLifetime

DbContext hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

optionsLifetime
ServiceLifetime

DbContextOptions hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

Döndürülenler

Birden çok çağrının zincirlenebilmesi için aynı hizmet koleksiyonu.

Örnekler

public void ConfigureServices(IServiceCollection services)
{
    var connectionString = "connection string to database";

    services.AddDbContext<MyContext>(options => options.UseSqlServer(connectionString));
}

Açıklamalar

ASP.NET Core gibi uygulamanızda bağımlılık ekleme özelliğini kullanırken bu yöntemi kullanın. Bağımlılık ekleme kullanmayan uygulamalar için doğrudan oluşturucuyla örnek oluşturmayı DbContext göz önünde bulundurun. Daha OnConfiguring(DbContextOptionsBuilder) sonra bir bağlantı dizesi ve diğer seçenekleri yapılandırmak için yöntemi geçersiz kılınabilir.

Entity Framework Core, aynı DbContext örneğinde birden çok paralel işlemin çalıştırılmasını desteklemez. Buna hem zaman uyumsuz sorguların paralel yürütülmesi hem de birden çok iş parçacığından açık eş zamanlı kullanım dahildir. Bu nedenle, her zaman zaman uyumsuz çağrıları hemen bekleyin veya paralel olarak yürütülen işlemler için ayrı DbContext örnekleri kullanın. Daha fazla bilgi ve örnek için bkz. DbContext iş parçacığı oluşturma sorunlarını önleme .

Daha fazla bilgi ve örnek için bkz. DbContext'i bağımlılık ekleme ile kullanma .

Şunlara uygulanır

AddDbContext<TContext>(IServiceCollection, Action<IServiceProvider,DbContextOptionsBuilder>, ServiceLifetime, ServiceLifetime)

Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder.

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDbContext<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<IServiceProvider,Microsoft.EntityFrameworkCore.DbContextOptionsBuilder>? optionsAction, Microsoft.Extensions.DependencyInjection.ServiceLifetime contextLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped, Microsoft.Extensions.DependencyInjection.ServiceLifetime optionsLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) where TContext : Microsoft.EntityFrameworkCore.DbContext;
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDbContext<TContext>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<IServiceProvider,Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> optionsAction, Microsoft.Extensions.DependencyInjection.ServiceLifetime contextLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped, Microsoft.Extensions.DependencyInjection.ServiceLifetime optionsLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) where TContext : Microsoft.EntityFrameworkCore.DbContext;
static member AddDbContext : Microsoft.Extensions.DependencyInjection.IServiceCollection * Action<IServiceProvider, Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> * Microsoft.Extensions.DependencyInjection.ServiceLifetime * Microsoft.Extensions.DependencyInjection.ServiceLifetime -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'Context :> Microsoft.EntityFrameworkCore.DbContext)
<Extension()>
Public Function AddDbContext(Of TContext As DbContext) (serviceCollection As IServiceCollection, optionsAction As Action(Of IServiceProvider, DbContextOptionsBuilder), Optional contextLifetime As ServiceLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped, Optional optionsLifetime As ServiceLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) As IServiceCollection

Tür Parametreleri

TContext

Kaydedilecek bağlam türü.

Parametreler

serviceCollection
IServiceCollection

IServiceCollection için hizmetler eklenir.

optionsAction
Action<IServiceProvider,DbContextOptionsBuilder>

bağlamını yapılandırmak DbContextOptions için isteğe bağlı bir eylemdir. Bu, türetilmiş bağlamınızdaki yöntemini geçersiz kılarak bağlam yapılandırmasını gerçekleştirmeye OnConfiguring(DbContextOptionsBuilder) bir alternatif sağlar.

Burada bir eylem sağlanırsa, OnConfiguring(DbContextOptionsBuilder) yöntem türetilmiş bağlamda geçersiz kılındıysa yine de çalıştırılır. OnConfiguring(DbContextOptionsBuilder) yapılandırma, burada gerçekleştirilen yapılandırmaya ek olarak uygulanır.

Seçeneklerin bağlamınıza geçirilebilmesi için, bağlamınız üzerinde bunu alıp DbContextOptions<TContext> temel oluşturucusuna geçiren bir oluşturucuyu DbContextkullanıma sunmanız gerekir.

contextLifetime
ServiceLifetime

DbContext hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

optionsLifetime
ServiceLifetime

DbContextOptions hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

Döndürülenler

Birden çok çağrının zincirlenebilmesi için aynı hizmet koleksiyonu.

Örnekler

public void ConfigureServices(IServiceCollection services)
{
    var connectionString = "connection string to database";

    services
        .AddEntityFrameworkSqlServer()
        .AddDbContext<MyContext>((serviceProvider, options) =>
            options.UseSqlServer(connectionString)
                   .UseInternalServiceProvider(serviceProvider));
}

Açıklamalar

ASP.NET Core gibi uygulamanızda bağımlılık ekleme özelliğini kullanırken bu yöntemi kullanın. Bağımlılık ekleme kullanmayan uygulamalar için doğrudan oluşturucuyla örnek oluşturmayı DbContext göz önünde bulundurun. Daha OnConfiguring(DbContextOptionsBuilder) sonra bir bağlantı dizesi ve diğer seçenekleri yapılandırmak için yöntemi geçersiz kılınabilir.

Entity Framework Core, aynı DbContext örneğinde birden çok paralel işlemin çalıştırılmasını desteklemez. Buna hem zaman uyumsuz sorguların paralel yürütülmesi hem de birden çok iş parçacığından açık eş zamanlı kullanım dahildir. Bu nedenle, her zaman zaman uyumsuz çağrıları hemen bekleyin veya paralel olarak yürütülen işlemler için ayrı DbContext örnekleri kullanın. Daha fazla bilgi ve örnek için bkz. DbContext iş parçacığı oluşturma sorunlarını önleme .

Daha fazla bilgi ve örnek için bkz. DbContext'i bağımlılık ekleme ile kullanma .

Bu aşırı yükleme, uygulamanın IServiceProvideröğesini sağlayan bir optionsAction öğesine sahiptir. Bu, birincil uygulama hizmeti sağlayıcısından iç hizmetlerini çözümlemek için Entity Framework Core ayarlamak istiyorsanız kullanışlıdır. Varsayılan olarak, Entity Framework'ün iç Entity Framework hizmetleri için kendi IServiceProvider varlıklarını oluşturmasına ve korumasına olanak tanıyan öğesini kullanmanızı AddDbContext<TContext>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime, ServiceLifetime) öneririz.

Şunlara uygulanır

AddDbContext<TContextService,TContextImplementation>(IServiceCollection, ServiceLifetime, ServiceLifetime)

Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder.

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDbContext<TContextService,TContextImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Microsoft.Extensions.DependencyInjection.ServiceLifetime contextLifetime, Microsoft.Extensions.DependencyInjection.ServiceLifetime optionsLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) where TContextService : class where TContextImplementation : Microsoft.EntityFrameworkCore.DbContext, TContextService;
static member AddDbContext : Microsoft.Extensions.DependencyInjection.IServiceCollection * Microsoft.Extensions.DependencyInjection.ServiceLifetime * Microsoft.Extensions.DependencyInjection.ServiceLifetime -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'ContextService : null and 'ContextImplementation :> Microsoft.EntityFrameworkCore.DbContext and 'ContextImplementation :> 'ContextService)
<Extension()>
Public Function AddDbContext(Of TContextService As Class, TContextImplementation As Class) (serviceCollection As IServiceCollection, contextLifetime As ServiceLifetime, Optional optionsLifetime As ServiceLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) As IServiceCollection

Tür Parametreleri

TContextService

Kapsayıcıdan bağlamı çözümlemek için kullanılacak sınıf veya arabirim.

TContextImplementation

Oluşturulacak somut uygulama türü.

Parametreler

serviceCollection
IServiceCollection

IServiceCollection için hizmetler eklenir.

contextLifetime
ServiceLifetime

DbContext hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

optionsLifetime
ServiceLifetime

DbContextOptions hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

Döndürülenler

Birden çok çağrının zincirlenebilmesi için aynı hizmet koleksiyonu.

Örnekler

public void ConfigureServices(IServiceCollection services)
{
    var connectionString = "connection string to database";

    services.AddDbContext<MyContext>(ServiceLifetime.Scoped);
}

Açıklamalar

ASP.NET Core gibi uygulamanızda bağımlılık ekleme özelliğini kullanırken bu yöntemi kullanın. Bağımlılık ekleme kullanmayan uygulamalar için doğrudan oluşturucuyla örnek oluşturmayı DbContext göz önünde bulundurun. Daha OnConfiguring(DbContextOptionsBuilder) sonra bir bağlantı dizesi ve diğer seçenekleri yapılandırmak için yöntemi geçersiz kılınabilir.

Entity Framework Core, aynı DbContext örneğinde birden çok paralel işlemin çalıştırılmasını desteklemez. Buna hem zaman uyumsuz sorguların paralel yürütülmesi hem de birden çok iş parçacığından açık eş zamanlı kullanım dahildir. Bu nedenle, her zaman zaman uyumsuz çağrıları hemen bekleyin veya paralel olarak yürütülen işlemler için ayrı DbContext örnekleri kullanın. Daha fazla bilgi ve örnek için bkz. DbContext iş parçacığı oluşturma sorunlarını önleme .

Daha fazla bilgi ve örnek için bkz. DbContext'i bağımlılık ekleme ile kullanma .

Şunlara uygulanır

AddDbContext<TContextService,TContextImplementation>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime, ServiceLifetime)

Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder.

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDbContext<TContextService,TContextImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder>? optionsAction = default, Microsoft.Extensions.DependencyInjection.ServiceLifetime contextLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped, Microsoft.Extensions.DependencyInjection.ServiceLifetime optionsLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) where TContextImplementation : Microsoft.EntityFrameworkCore.DbContext, TContextService;
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDbContext<TContextService,TContextImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> optionsAction = default, Microsoft.Extensions.DependencyInjection.ServiceLifetime contextLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped, Microsoft.Extensions.DependencyInjection.ServiceLifetime optionsLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) where TContextImplementation : Microsoft.EntityFrameworkCore.DbContext, TContextService;
static member AddDbContext : Microsoft.Extensions.DependencyInjection.IServiceCollection * Action<Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> * Microsoft.Extensions.DependencyInjection.ServiceLifetime * Microsoft.Extensions.DependencyInjection.ServiceLifetime -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'ContextImplementation :> Microsoft.EntityFrameworkCore.DbContext and 'ContextImplementation :> 'ContextService)
<Extension()>
Public Function AddDbContext(Of TContextService, TContextImplementation) (serviceCollection As IServiceCollection, Optional optionsAction As Action(Of DbContextOptionsBuilder) = Nothing, Optional contextLifetime As ServiceLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped, Optional optionsLifetime As ServiceLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) As IServiceCollection

Tür Parametreleri

TContextService

Kapsayıcıdan bağlamı çözümlemek için kullanılacak sınıf veya arabirim.

TContextImplementation

Oluşturulacak somut uygulama türü.

Parametreler

serviceCollection
IServiceCollection

IServiceCollection için hizmetler eklenir.

optionsAction
Action<DbContextOptionsBuilder>

bağlamını yapılandırmak DbContextOptions için isteğe bağlı bir eylemdir. Bu, türetilmiş bağlamınızdaki yöntemini geçersiz kılarak bağlam yapılandırmasını gerçekleştirmeye OnConfiguring(DbContextOptionsBuilder) bir alternatif sağlar.

Burada bir eylem sağlanırsa, OnConfiguring(DbContextOptionsBuilder) yöntem türetilmiş bağlamda geçersiz kılındıysa yine de çalıştırılır. OnConfiguring(DbContextOptionsBuilder) yapılandırma, burada gerçekleştirilen yapılandırmaya ek olarak uygulanır.

Seçeneklerin bağlamınıza geçirilebilmesi için, bağlamınız üzerinde bunu alıp DbContextOptions<TContext> temel oluşturucusuna geçiren bir oluşturucuyu DbContextkullanıma sunmanız gerekir.

contextLifetime
ServiceLifetime

DbContext hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

optionsLifetime
ServiceLifetime

DbContextOptions hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

Döndürülenler

Birden çok çağrının zincirlenebilmesi için aynı hizmet koleksiyonu.

Örnekler

public void ConfigureServices(IServiceCollection services)
{
    var connectionString = "connection string to database";

    services.AddDbContext<MyContext>(options => options.UseSqlServer(connectionString));
}

Açıklamalar

ASP.NET Core gibi uygulamanızda bağımlılık ekleme özelliğini kullanırken bu yöntemi kullanın. Bağımlılık ekleme kullanmayan uygulamalar için doğrudan oluşturucuyla örnek oluşturmayı DbContext göz önünde bulundurun. Daha OnConfiguring(DbContextOptionsBuilder) sonra bir bağlantı dizesi ve diğer seçenekleri yapılandırmak için yöntemi geçersiz kılınabilir.

Entity Framework Core, aynı DbContext örneğinde birden çok paralel işlemin çalıştırılmasını desteklemez. Buna hem zaman uyumsuz sorguların paralel yürütülmesi hem de birden çok iş parçacığından açık eş zamanlı kullanım dahildir. Bu nedenle, her zaman zaman uyumsuz çağrıları hemen bekleyin veya paralel olarak yürütülen işlemler için ayrı DbContext örnekleri kullanın. Daha fazla bilgi ve örnek için bkz. DbContext iş parçacığı oluşturma sorunlarını önleme .

Daha fazla bilgi ve örnek için bkz. DbContext'i bağımlılık ekleme ile kullanma .

Şunlara uygulanır

AddDbContext<TContextService,TContextImplementation>(IServiceCollection, Action<IServiceProvider,DbContextOptionsBuilder>, ServiceLifetime, ServiceLifetime)

Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs
Kaynak:
EntityFrameworkServiceCollectionExtensions.cs

Verilen bağlamı içinde IServiceCollectionbir hizmet olarak kaydeder.

public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDbContext<TContextService,TContextImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<IServiceProvider,Microsoft.EntityFrameworkCore.DbContextOptionsBuilder>? optionsAction, Microsoft.Extensions.DependencyInjection.ServiceLifetime contextLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped, Microsoft.Extensions.DependencyInjection.ServiceLifetime optionsLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) where TContextImplementation : Microsoft.EntityFrameworkCore.DbContext, TContextService;
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddDbContext<TContextService,TContextImplementation>(this Microsoft.Extensions.DependencyInjection.IServiceCollection serviceCollection, Action<IServiceProvider,Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> optionsAction, Microsoft.Extensions.DependencyInjection.ServiceLifetime contextLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped, Microsoft.Extensions.DependencyInjection.ServiceLifetime optionsLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) where TContextImplementation : Microsoft.EntityFrameworkCore.DbContext, TContextService;
static member AddDbContext : Microsoft.Extensions.DependencyInjection.IServiceCollection * Action<IServiceProvider, Microsoft.EntityFrameworkCore.DbContextOptionsBuilder> * Microsoft.Extensions.DependencyInjection.ServiceLifetime * Microsoft.Extensions.DependencyInjection.ServiceLifetime -> Microsoft.Extensions.DependencyInjection.IServiceCollection (requires 'ContextImplementation :> Microsoft.EntityFrameworkCore.DbContext and 'ContextImplementation :> 'ContextService)
<Extension()>
Public Function AddDbContext(Of TContextService, TContextImplementation) (serviceCollection As IServiceCollection, optionsAction As Action(Of IServiceProvider, DbContextOptionsBuilder), Optional contextLifetime As ServiceLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped, Optional optionsLifetime As ServiceLifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped) As IServiceCollection

Tür Parametreleri

TContextService

Kapsayıcıdan bağlamı çözümlemek için kullanılacak sınıf veya arabirim.

TContextImplementation

Oluşturulacak somut uygulama türü.

Parametreler

serviceCollection
IServiceCollection

IServiceCollection için hizmetler eklenir.

optionsAction
Action<IServiceProvider,DbContextOptionsBuilder>

bağlamını yapılandırmak DbContextOptions için isteğe bağlı bir eylemdir. Bu, türetilmiş bağlamınızdaki yöntemini geçersiz kılarak bağlam yapılandırmasını gerçekleştirmeye OnConfiguring(DbContextOptionsBuilder) bir alternatif sağlar.

Burada bir eylem sağlanırsa, OnConfiguring(DbContextOptionsBuilder) yöntem türetilmiş bağlamda geçersiz kılındıysa yine de çalıştırılır. OnConfiguring(DbContextOptionsBuilder) yapılandırma, burada gerçekleştirilen yapılandırmaya ek olarak uygulanır.

Seçeneklerin bağlamınıza geçirilebilmesi için, bağlamınız üzerinde bunu alıp DbContextOptions<TContext> temel oluşturucusuna geçiren bir oluşturucuyu DbContextkullanıma sunmanız gerekir.

contextLifetime
ServiceLifetime

DbContext hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

optionsLifetime
ServiceLifetime

DbContextOptions hizmetinin kapsayıcıya kaydedildiği yaşam süresi.

Döndürülenler

Birden çok çağrının zincirlenebilmesi için aynı hizmet koleksiyonu.

Örnekler

public void ConfigureServices(IServiceCollection services)
{
    var connectionString = "connection string to database";

    services
        .AddEntityFrameworkSqlServer()
        .AddDbContext<MyContext>((serviceProvider, options) =>
            options.UseSqlServer(connectionString)
                   .UseInternalServiceProvider(serviceProvider));
}

Açıklamalar

ASP.NET Core gibi uygulamanızda bağımlılık ekleme özelliğini kullanırken bu yöntemi kullanın. Bağımlılık ekleme kullanmayan uygulamalar için doğrudan oluşturucuyla örnek oluşturmayı DbContext göz önünde bulundurun. Daha OnConfiguring(DbContextOptionsBuilder) sonra bir bağlantı dizesi ve diğer seçenekleri yapılandırmak için yöntemi geçersiz kılınabilir.

Entity Framework Core, aynı DbContext örneğinde birden çok paralel işlemin çalıştırılmasını desteklemez. Buna hem zaman uyumsuz sorguların paralel yürütülmesi hem de birden çok iş parçacığından açık eş zamanlı kullanım dahildir. Bu nedenle, her zaman zaman uyumsuz çağrıları hemen bekleyin veya paralel olarak yürütülen işlemler için ayrı DbContext örnekleri kullanın. Daha fazla bilgi ve örnek için bkz. DbContext iş parçacığı oluşturma sorunlarını önleme .

Daha fazla bilgi ve örnek için bkz. DbContext'i bağımlılık ekleme ile kullanma .

Bu aşırı yükleme, uygulamanın IServiceProvideröğesini sağlayan bir optionsAction öğesine sahiptir. Bu, birincil uygulama hizmeti sağlayıcısından iç hizmetlerini çözümlemek için Entity Framework Core ayarlamak istiyorsanız kullanışlıdır. Varsayılan olarak, Entity Framework'ün iç Entity Framework hizmetleri için kendi IServiceProvider varlıklarını oluşturmasına ve korumasına olanak tanıyan öğesini kullanmanızı AddDbContext<TContextService,TContextImplementation>(IServiceCollection, Action<DbContextOptionsBuilder>, ServiceLifetime, ServiceLifetime) öneririz.

Şunlara uygulanır