geoff swartz
geoff swartz

Reputation: 5965

how to determine runtime for .net core web app

I'm trying to migrate an mvc app to a .net core application. In my mvc app I use Ninject to set up my data sources and the connection strings. The logic is something like:

public static string GetConnectString(IContext context){
      var httpContext = context.Kernel.Get<HttpContextBase>();

      if (ConfigurationManager.AppSettings["environmentMode"] == "local")
          return DataConnect.LocalConnectString;

      if (ConfigurationManager.AppSettings["environmentMode"] == "development")
          return DataConnect.StagingConnectString;

      return DataConnect.LiveConnectString;
}

This is in my NinjectWebCommon.cs class and called from the RegisterServices method.

So now in .net core I have a Startup.cs with the ConfigureServices method so I can do something like:

services.AddDbContext<DBContext>(opt => opt.UseSqlServer(DataConnect.StagingConnectString));

But I'm not sure how to determine the environment - local, staging or live - to provide the correct connect string.

Upvotes: 0

Views: 73

Answers (1)

Rocher Kong
Rocher Kong

Reputation: 106

The configuration file is the appsettings.json and you can have multiple files, like appsettings.Production.json etc, which will be loaded and override settings from the appsettings.json .

Upvotes: 1

Related Questions