Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EFCore InternalServiceProvider is not supported #24

Closed
PatrykPlewaOfficial opened this issue Mar 9, 2023 · 1 comment · Fixed by #37
Closed

EFCore InternalServiceProvider is not supported #24

PatrykPlewaOfficial opened this issue Mar 9, 2023 · 1 comment · Fixed by #37
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@PatrykPlewaOfficial
Copy link

Background

QueryableValues are not working when using EFCore InternalServiceProvider due to missing service registration in the DI container.

Unable to resolve service for type 'BlazarTech.QueryableValues.IQueryableFactory'.
This is often because no database provider has been configured for this DbContext.
A provider can be configured by overriding the 'DbContext.OnConfiguring' method
or by using 'AddDbContext' on the application service provider.
If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.

EF Core registration

DI registration of EF is given this way:

services.AddDbContext<TestDbContext>((provider, builder) =>
        {
            builder.UseSqlServer(connectionString, opt =>
            {
                opt.UseQueryableValues();
            });
            builder.UseInternalServiceProvider(EntityFrameworkServices.Build(provider));
        });

public static class EntityFrameworkServices
{
    private static IServiceProvider _efServices;

    public static IServiceProvider Build(IServiceProvider serviceProvider)
    {
        if (_efServices != null)
            return _efServices;

        var efServices = new ServiceCollection()
            .AddEntityFrameworkSqlServer();

        return _efServices = efServices.BuildServiceProvider();
    }
}

Test environment

.NET 6 runtime

<PackageReference Include="BlazarTech.QueryableValues.SqlServer" Version="6.5.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.5" />

Initial Investigation

Looks like the method QueryableValuesSqlServerExtension.ApplyServices is called on the instance of IServiceCollection that is not really taking part in the creation of the ServiceProvider since the instance of the ServiceProvider has already been built manually.

@yv989c
Copy link
Owner

yv989c commented Mar 10, 2023

Hi @PatrykPlewaOfficial , thanks for the information. I'll take a look at it when I get a chance.

@yv989c yv989c self-assigned this Jun 19, 2023
@yv989c yv989c added the enhancement New feature or request label Jun 19, 2023
@yv989c yv989c added this to the v1.0.11 milestone Jun 19, 2023
This was referenced Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants