Grigory Zhadko
Grigory Zhadko

Reputation: 1828

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

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.

Upvotes: 8

Views: 2213

Answers (1)

Dimitris Maragkos
Dimitris Maragkos

Reputation: 11302

Is there an analog of method app.Environment.IsDevelopment() before building the WebApplication?

Yes:

var builder = WebApplication.CreateBuilder(args);

var isDevelopment = builder.Environment.IsDevelopment();

// ...

Upvotes: 15

Related Questions