Skip to content

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

Closed

Description

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions