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

[ASP.NET Core Dependency injection] How can I get IServiceProvider outside controller ?

$
0
0

Hi everyone,

I try to work with native dependency injection of ASP.NET Core 1.0. I work with rc1 update 1 version.

I have an n-tiers application. I would like to get IServiceProvider into DataLayer to obtain my DbContext by service with AddTransient.

Many examples show how to get my DbContext with my controllers like this :

public MyController(IDbContext dbContext)
{
}

This exemple works very well. But I don't want to use this method because I have to pass my DbContext through my layers.

My question is : How can I get IServiceProvider outside ASP.NET Core scope ?

Thank you for your help.

Greg


Viewing all articles
Browse latest Browse all 9386

Trending Articles



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