Due to the pandemic Urban Engine is no longer holding CoWorking Night on a weekly basis. CoWorking Night is now held once a month and all scheduling is done via Google Calendar; therefore, this project is no longer needed. However, this code will be publicly archived for reference in the event any devs want to see how we planning to to handle this use case.
This section outlines information relating to configuring or deploying the UrbanEngineApi application.
For provisioning resources in Azure the following script is available if running locally:
From the root directory run the following command in PowerShell:
& ./scripts/UrbanEngineApi-deploy-azure.ps1
NOTE: You will need Azure PowerShell installed if you want to run this script. Documentation on this is available at Install Azure PowerShell.
In your local development environment most configuration settings will be managed via UserSecrets
in a local secrets.json
file. The Microsoft.Extensions.Configuration.UserSecrets
NuGet package enables this for us. There is a script located in scripts/set-secrets-local.ps1 that will set this up in your local development environment.
From the root folder of this repository run the following command in PowerShell:
& ./scripts/set-secrets-local.ps1
You may be prompted to specify certain values such as the database password.
In production we will be using Azure KeyVault
to store secrets. The set-secrets-prod.ps1
script can be used to set the configuration values in the KeyVault. This script will affect production; therefore, please be sure to only run this when ready.
From the root folder of this repository run the following command in PowerShell:
& ./scripts/set-secrets-prod.ps1
Also NOTE: In the appsettings.json the setting KeyVaultName
indicates the name of the KeyVault to use. Again, please make sure this settings is correct before deploying to production.
Be sure to update the set-secrets-local.ps1
and set-secrets-prod.ps1
scripts with any additional settings you add to the project. You can store any configuration values as secrets, they do not necessarily have to be just secrets.
This section will contain any notes to be aware of for developing Urban Engine API
To make things consistent objects in the Results folder are used. Use this to return responses from API endpoints to provide consistent return types
To provide a common response when exceptions occur and to ensure exceptions are logged and sensitive error messages are not returned to the client
an exception handler is added in the Startup.cs file. This allows the capture of any exceptions
thrown by controller endpoints without having to add try/catch
and logging
statements in your controllers themselves.
Example:
// see Configure method in Startup.cs
app.UseExceptionHandler(errorApp =>
{
errorApp.Run(async context =>
{
// ...see implementation details in Startup.cs file...
});
});
When the UrbanEngineApi starts up it is currently set to call Migrate
to update the database. Whether this is run or not is controll by an Environment Variable
called APPLY_MIGRATIONS
and if this is set to the value of True
then Migrations will be applied on application start up. This is good to have turned on for any
development or testing environments but should be disabled in Production and applied only when expected. To see the code where migrations are run go to
the Program.cs file in the UrbanEngineApi project and look for the CreateOrMigrateDatabase
method.
Open a command prompt
cd to the src\UrbanEngine.Infrastructure
directory
In the command window type dotnet ef --help
to ensure you have the dotnet ef tool installed
If EF tools are not installed you'll need to install them using
dotnet tool install --global dotnet-ef
Run the following command, change the <yourmigrationname>
to be a name to indicate what is going into this migration
dotnet ef migrations add <yourmigrationname> --startup-project ../UrbanEngine.Web/UrbanEngine.Web.csproj --project UrbanEngine.Infrastructure.csproj --output-dir Data/Migrations
If working with the local SQL Lite database you'll have to delete the *.db file first as well
The SeedDataGenerator is used to seed the database with any initial data. Use this to add any data that should always be present in the database
A docker compose file exists to help spin up a docker container that runs PostgresSQL. Follow the steps to run the database locally in your dev environment.
Open a command prompt
cd to the UrbanEngineApi
directory
Ensure that Docker is running
Run the following command
& scripts\start-postgres-local.ps1
Open pgAdmin
and ensure you can connect to the database locally
To stop the database when you are finished run the following
& scripts\stop-postgres-local.ps1
UrbanEngine.Core
projectEntity
UrbanEngine.SharedKernel.Data.EntityBase
UrbanEngine.Infrastructure
projectData\Configuration
EntityBaseConfiguration
Configure
method and add in any mappingsEntityBase
UrbanEngine.Infrastructure
projectEfRepository<T>
UrbanEngine.Web
project and right click, go to properties. Click Debug, If it does not already exist add an environment variable APPLY_MIGRATIONS
and set the value to be true
pgAdmin
and ensure your changes are refelectedExplore other options with dotnet ef
tools for additional options
UrbanEngine.Core
BaseSpecification<T>
UrbanEngine.Core
Manager
ManagerBase<TEntity>
base classIManager<TEntity>
UrganEngine.Core
DetailDTO
and ListItemDTO
UrbanEngine.Core
IRequest
interface passing in the expected output to receive when the message is processedUrbanEngine.Core
IRequestHandler
and specify the type of message your handler is to process and the expected output to return. The output must match the same output specified in your message for IRequest
UrbanEngine.Web
Configuration\AutoMapperProfile
Startup.cs
, we need to add in Dependency Injection in the ConfigureServices
method to register your repository and managerUrbanEngine.Web
IMediator
as dependency and let your controller endpoints receive messages and publish to Mediatr to processControllerBase
UrbanEngine.Web
and hit swagger
and test your your controller. If everything is wired up correctly you should be able to test out everything end to endUrbanEngine.Tests
TestScope<T>
where T is the class you want to write the test for[TestMethod, TestCategory(TestCategory.Unit)]