- Build
Ctrl+F5π - Migrate
update-databaseπ - Hit F5 π
To generate a migration script run Script-Migration
The project follows a clean architecture design structure. You can see from the naming convention of the top level folders this gives us a nice easy structure to locate code quickly. Areas - Code - Data - Domain
Areas hold the application and presentation models and views.
This is the infrastructure layer
This contains anything related to persistence
The domain layer has its own folder self named. This contains the domain entities.
To use Google and Facebook login you need to ensure the secrets are added
dotnet user-secrets set "Authentication:Facebook:AppId" "appid"
dotnet user-secrets set "Authentication:Facebook:AppSecret" "secret"
dotnet user-secrets set "Authentication:Google:ClientId" "<client-id>"
dotnet user-secrets set "Authentication:Google:ClientSecret" "<client-secret>"
You can choose between MSSQL or PostgreSQL databases and both connection strings have entries in the appsettings.json file.
You can switch between the two by setting the ActiveConnectionString value to the name of the connection string that you want to use.
Select MssqlConnection | PostgresConnection depending on which one you want to use.
Tested with Postgres version for windows 14.5.1
You'll have to remove any existing migration you did for MSSQL and then you can do this in the package manager:
Add-Migration InitialPersistedGrantDbMigration -c ApplicationDbContext -o Data/Migrations
update-databaseNow run project and it will use postgres
You can access the local health check endpoint on /HealthChecks-UI, this will be available over the internet for development.
There are three new endpoints for health check
/HealthChecks-Api, this is used by the UI/HealthChecks, this is the Json output of the healthcheck and it collated by the API endpoint/Status, this is a simple Healthy, Degraded or Unhealthy status of the site
Within the application code there is now a HealthChecks folder with an Example Health check this is configured as below along with a PostgreSQL health Check
builder.Services.AddHealthChecks()
.AddNpgSql(connectionString, name: "Database")
.AddCheck<ExampleHealthCheck>("Example");
For more information on Health Check UI see the GitHub repository https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks
Serilog is used as the logging and enriching framework, this is configured using the application settings and by default only logs to the Console
A helpful article on logging can be found on https://benfoster.io/blog/serilog-best-practices/
The Swashbuckle UI can be found at /Swagger/index.html and the JSON data can be found at /swagger/v0.9/swagger.json
The Swashbuckle.AspNetCore package is used to deliver Open API specifications and the Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer NuGet is used to generate the version information.
Controllers can be decorated with various attributes to aid in the generation of Open API documentation:
ApiVersionAttribute- is used on the Controller to denote the version of that controller.ProducesAttribute- is used on a method to define the data type, for example"application/json"for JSON formatted data.ProducesResponseTypeAttribute- is used on methods to denote the HTTP response codes supported as well as the object returned.
XML comments on the Controller Class, Controller Methods, Model Class and Model Properties are used to document what the classes are used for and their functions.
This is enabled on the Properties page of the Project under the Output check the Documentation file box and enter the path bin\$(Configuration)\$(TargetFramework)\$(MSBuildThisFileName).xml for the auto generated xml document.
More information of documenting can be found in the following Microsoft articles
- https://learn.microsoft.com/en-gb/dotnet/csharp/language-reference/xmldoc/recommended-tags
- https://learn.microsoft.com/en-gb/dotnet/csharp/language-reference/compiler-options/output
The test API uses Hashids, a non cryptographic encoded string, that can be used to obfuscate database Ids. Examples of this can be found in YouTubes URIs https://youtu.be/tSuwe7FowzE where tSuwe7FowzE is a Hashid
The URI above is also a video on Hashids that explains their use. These are demonstrated in API V2 as a breaking change from 1 to 2.
Get the Chrome Selenium IDE extension: Selenium IDE
Once this is installed you can record and create some basic front end tests. These can be used as smoke tests for the local environment.
- Fireup the local development environment
- Open the SeleniumIDE chrome extension
- Choose "Open an existing project" from the IDE
- Select the
Lifebuddy.sidetest suite fromsrc\Marvin.Tests\SeleniumIDE - Run the tests, and you should see all green π
Checks are able to validate for Contract Exceptions and Business rule errors contact Exceptions are thrown upon Validate() being called and therefore all contract exceptions can be caught in one go.
Check.ArgNullContract(() => object1).ArgNullContract(() => object2).Validate();
This is based on the following blog https://blog.getpaint.net/2008/12/06/a-fluent-approach-to-c-parameter-validation/
A list of useful resources for the project