1
I’m updating an ASP.NET Framework API to ASP.NET Core and I’m stuck in a problem.
No. NET Framework used the following:
public GmailConnection(){
serverCredentialPath = HostingEnvironment.MapPath("~/Credentials/Google/Gmail/"); //Variavel da classe sendo atribuida pelo mapeamento
serverClientSecret = HostingEnvironment.MapPath("~/APIS/Google/Gmail/client_secret.json"); //Variavel da classe sendo atribuida pelo mapeamento
}
But in ASP.NET Core I can only access to IHostingEnvironment
through the Controller:
private IHostingEnvironment _env;
public MarketingController(IHostingEnvironment env)
{
_env = env;
string path = env.WebRootPath;
}
How do I gain access to IHostingEnvironment
through a class other than Controller?
would not be the case to assign this value there is an abstract class and static properties?
– Leandro Angelo
Yes, but how to receive the
IHostingEnvironment
in that statistical class?– Leonardo Bonetti
I’ve tried so many ways...
– Leonardo Bonetti
Where will this class be? It is not clear to me where you want to use the
IHostingEnvironment
. One option may be to inject via constructor.– Barbetta
Barbetta, then, in the old version of my program, was inside the constructor of a class called
GmailConnection
, look at the issue. I need to receive these values inside the constructor or through a static class, the problem is that I cannot inject it via constructor...– Leonardo Bonetti