You can simply inject IHostingEnvironment into the startup constructor of your Startup.cs
Like So
private readonly IHostingEnvironment _environment;
public Startup(IConfiguration configuration,IHostingEnvironment environment)
{
_environment = environment;
Configuration = configuration;
}
Then you can use the private IHostingEnvironment inside your configures services method .
public void ConfigureServices(IServiceCollection services)
{
if(!_environment.IsDevelopment())
services.AddMemoryCache();
}
EDIT :
After rereading the question the cache tags should be disabled aswell.
I would suggest adding a flag inside your appsettings.devlopment.json called"PageCachingEnabled": "false" .
On the view I would then inject the configuration like so
@using Microsoft.Extensions.Configuration
@inject IConfiguration Configuration
<cache [email protected](Configuration["PageCachingEnabled"]) expires-after="@TimeSpan.FromSeconds(3600)">