Here's the full setup guide for a Perigee Application with included API hosting, CORS, and swagger. You can download the completed result here:
1- Create an ASP.NET Core Web API project
Using Visual Studio we are going to create a new project. We want to select "ASP.NET Core Web API".
2- Configure the application as needed
When you get to configuration, feel free to override these settings as desired. An example configuration of this is shown below.
3 - Setup Program.cs
After opening Program.cs - the template created a project for us which looks like this:
We're going to add a few things to this basic setup to get it fully configured for Perigee.
We're going to add the ThreadRegistry instance to the builder host services.
We need to use Serilog.
Let's add CORS for cross origin.
Instead of running the application in synchronous mode we capture the asynchronous task handle.
Pass it to Perigee.
The "new" Program.cs
usingPerigee;usingSerilog;var builder =WebApplication.CreateBuilder(args);// Add services to the container.builder.Services.AddSingleton(ThreadRegistry.Instance);builder.Host.UseSerilog();//Controllersbuilder.Services.AddControllers();//SwaggerGen - https://aka.ms/aspnetcore/swashbucklebuilder.Services.AddEndpointsApiExplorer().AddSwaggerGen();//Build / configurevar app =builder.Build();if (app.Environment.IsDevelopment()) app.UseSwagger().UseSwaggerUI();// HTTPS/Auth/Controllers/Corsapp.UseHttpsRedirection().UseAuthorization();app.MapControllers();app.UseCors(o =>o.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());app.UseSerilogRequestLogging();//Run async!var taskRunner =app.RunAsync();//Pass the taskRunner to Perigee initializationPerigeeApplication.ApplicationNoInit("Hosted Perigee App", (c) => { //Add and configure away //Sample running configc.AddRecurring("Running", (c, l) => { l.LogInformation("I'm running"); });}, HostTask: taskRunner);/*********************************************************************/// TODO:// Using the package manager console, or the Nuget GUI: install-package Perigee// Add AppSettings.json and set the "Copy To Output Directory" in the Properties inspector to "Copy Always"/*********************************************************************/
4 - Installation
We need to install Perigee as a dependency.
Either use the Nuget GUI or the Package Manager Console and type install-package Perigee
5- AppSettings.json
The AppSettings.json file is slightly different when using .NET hosting, as we want to turn off the debug level logging for Serilog and AspNetcore.
Depending on the template and .NET version you selected the appsettings.json file may or may not exist. Feel free to download and drop in the one provided if it is not automatically included.
As always, make sure this is set to "Copy Always" in the Property Inspector.
6- License file
Please copy your license file into the project root and set to "Copy Always"
Running the application
After clicking "Run" - You should see Swagger in the default browser, and the Perigee application console window with .NET hosting running.