Skip to content

How to make Depency Injection with AddDbContext in .NET Core #18

@eddorneles

Description

@eddorneles

I've checked the "source_files" sample but it was to simple for my understanding...

The MySQL provider and Npgsql providers suggests create the database connection inside the Context class, something like:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 
=> optionsBuilder.UseNpgsql("Host=my_host;Database=my_db;Username=my_user;Password=my_pw");

And in the ConfigureService method of the Startup class, some code like this:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<OracleContext>().BuildServiceProvider();
}

So, I'd like to know if is possible to make the dependency injection like that, does exist some method like the "UseNpgsql()" in Oracle.ManagedDataAccess.Core? In fact, does this driver support Entity Framework Core Object Mapping? Or is it only for database access purposes with native queries?

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions