How do I use the IHostingEnvironment
interface without initiating it in a constructor?
my Startup.cs:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
if (env.IsDevelopment())
{
// This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
builder.AddApplicationInsightsSettings(developerMode: true);
}
Configuration = builder.Build();
}
My Class:
public class FileReader
{
// I don't want to initiate within a constructor
public string ReadFile(string fileName)
{
// this is wrong! how can I use it?
var filename = Path.Combine(IHostingEnvironment.WebRootPath, fileName);
}
}