KEMBAR78
Allow services to be easily resolved from the application service provider from within EF Core · Issue #13540 · dotnet/efcore · GitHub
Skip to content

Allow services to be easily resolved from the application service provider from within EF Core #13540

@chernihiv

Description

@chernihiv

I try to resolve CustomMigrationsSqlGenerator with IMyCustomService but it throws an exception.

I have overridden partially logic inside SqlServerMigrationsSqlGenerator, but for my goal I need to resolve extra service inside, e.g:

class CustomMigrationsSqlGenerator : SqlServerMigrationsSqlGenerator
{
    public CustomMigrationsSqlGenerator (
        IMyCustomService service,
        MigrationsSqlGeneratorDependencies dependencies,
        IMigrationsAnnotationProvider migrationsAnnotations)
        : base(dependencies, migrationsAnnotations)  { }

}

it throws an exception
System.InvalidOperationException: Unable to resolve service for type 'IMyCustomService' while attempting to activate 'CustomMigrationsSqlGenerator'.

IMyCustomService is registered as:

...
services.AddScoped<IMyCustomService, MyCustomService>();
...

Further technical details

EF Core: Microsoft.EntityFrameworkCore 2.1.4
Database Provider: Microsoft.EntityFrameworkCore.SqlServer 2.1.4
Operating system: Windows 10 Pro 1803, 17134.285
IDE: Visual Studio 2017 15.8.6

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions