Home > Blockchain >  Call Environment.IsDevelopment() before building WebApplication in Asp.Net core 7
Call Environment.IsDevelopment() before building WebApplication in Asp.Net core 7

Time:01-24

I have an Asp.net core 7 application. Is there an analog of method app.Environment.IsDevelopment() before building the WebApplication?

var builder = WebApplication.CreateBuilder(args);

// Can I call IsDevelopment() here?

var app = builder.Build();
if (app.Environment.IsDevelopment())
{
    //...
}

I know that I can use Environment Variable, but I wanted to know if there is an already existing standard approach.

CodePudding user response:

Yes:

var builder = WebApplication.CreateBuilder(args);

var isDevelopment = builder.Environment.IsDevelopment();

// ...
  • Related