Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Dependency Injection for ApplicationDbContext

$
0
0

I'm having a problem with socket leaks in Azure....

This is the current way I do DI in my controllers:

private readonly ApplicationDbContext _context;
public SomeController(ApplicationDbContext context)
{_context = context;}

On of stackoverflow users suggested that I'm doing it wrong and that I should do this:

using (var scope = _scopeFactory.CreateScope())
{var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();}

But Microsoft's tutorials use the way I'm handling it....

Can someone plesae explain what is the difference and which way is better?

http://stackoverflow.com/questions/42104788/azure-socket-leaks

Thanks a lot


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>