dotnet/efcore

SqlServerConnection with DependencyInjection

Closed this issue · 2 comments

Hi,

I'm using a subclassed SqlServerConnection as described in #1629. Further I inject a service named ContextService:

public ApplicationSqlServerConnection(IDbContextOptions options, ILogger<SqlServerConnection> logger, ContextService contextService)
: base(options, logger)
{
   ContextService = contextService;
}

The service is registered as scoped:
services.AddScoped<ContextService>();

In a Controller I inject the ContextService as well. Problem is, that the injected ContextServices are not the same objects. What am I doing wrong?

Further technical details

EF Core version: 1.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Win10
IDE: Visual Studio 2017

@audacity76 This doesn't seem to be related to EF--you might want to try asking here: https://github.com/aspnet/DependencyInjection

That being said, I suspect that more information will be needed to figure out what is going on--a full code listing or project would help, or at least the code that is configuring D.I. and MVC and registering services.

@ajcvickers Thought it might be because DbContext is using its internal service provider. Other Services inject the ContextService correctly.