Multiple Environments

Multiple Environments Optional

Wrapt templates are configured with Development (StartupDevelopment) and Production (Startup) environments by default, with the ability to add as many additional environments as you'd like.

The project will run StartupDevelopment locally by default using an in-memory database. This environment should generally not be connected to a live database to ensure that devs will be able to clone your API down and run the solution without needing to go through additional database set up.

Additional environments can be add added using an Environments list in your initial build file. This will use a multiple startup approach as described in the aspnetcore docs. This means that there will be a Startup{EnvironmentName}.cs class, and appsettings.{environment}.json file, and a launchsettings.json profile added for each environment.

Environment Properties

NameRequiredDescriptionDefault
EnvironmentNameYesThe name of the environment that will set ASPNETCORE_ENVIRONMENT, the suffix of your Startup.cs etc. Note that Development and Startup are reserved strings for the in memory and production environments respectively. Startup can be used to add settings to the production environment.None
ConnectionStringYesThe connection string for the database. The connection string will just be added in between quotes and treated like a string, so will need to be valid in that format. Backslashes will automtically be escaped for you.None
ProfileNameYesThe name of the profile that is added into your launchsettings.json to run this environmentNone

IMPORTANT

Note that the connection strings will currently be added to appsettings.{environment}.json, so they will be committed to source control. You should NOT be adding anything with credentials in here.

There are plans to support secret manager and integration with external secret managers in AWS, Azure, etc. in the future.

Example

In this example, we are setting up QA, Staging, and Local environments in addition to the default Startup and Development environments. Development does not have to be specified here, but we can use Startup to specify our production settings, as we are in this case.

Note that the Local environment here would be using a local db stored on my computer which is separate from the Development environment which will use an in memory database.

Environments:
  - EnvironmentName: Startup
    ConnectionString: "Data Source=prodserver;Initial Catalog=MyDbName;Integrated Security=True;Encrypt=True;TrustServerCertificate=True;"
    ProfileName: Prod
  - EnvironmentName: Qa
    ConnectionString: "Data Source=qaserver;Initial Catalog=MyDbName;Integrated Security=True;Encrypt=True;TrustServerCertificate=True;"
    ProfileName: Qa
  - EnvironmentName: Staging
    ConnectionString: "Data Source=stagingserver;Initial Catalog=MyDbName;Integrated Security=True;Encrypt=True;TrustServerCertificate=True;"
    ProfileName: Staging
  - EnvironmentName: Local
    ConnectionString: "Data Source=localhost\SqlExpress;Initial Catalog=MyDbName;Integrated Security=True;Encrypt=True;TrustServerCertificate=True;"
    ProfileName: Local