In my startup.cs class I have a check to see if it's DEV environment and has a lot of key-value pairs in my appsettings.json and appsettings.development.json file.
however I want to encapsulate some code that only runs in the DEV environment and when deployment to either UAT, TEST or LIVE the code is not deployed.
how can this be achieved?
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseMigrationsEndPoint();
}
else
{
app.UseHsts();
}
And have a class, as this as a value in my class to get which URL the subdomain runs (which also would be the value of the roles in my IDENTITY database
private string SubDomain(HttpContext httpContext)
{
HttpRequest request = httpContext.Request;
string url = request.Headers["Host"];
string subDomainUrl = url.Replace("https://", "").Split('/')[0];
//I want to be able to get my domain based on http://localhost:44312/?role=adminUsers //so if it's running on localhost and the role is admin users this only would be executed locally, as the remote URL has http://adminusers.mydomain.com
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<InjectMyClassHere>(); //My class or interface goes here
I hope this is clear. How can I achieve this? ie have this class only execute in DEV and not deployed in UAT, TEST, OR LIVE environments