Application Api
The Foundation Every Arch Deployment Depends On
ASP.NET
Arch is built on the ASP.NET platform. To get started developing with Arch, first add the Application Api to your program. The initial calls that set up the Application Api also set up the entire Arch framework.
NuGet Setup
Add NuGet package TriunniaLabs.Arch.Microservice to your project. This brings in all the necessary framework code and the Application Api clients.

Note that we use our own NuGet package feed, which you must add as a package source in your environment.
Host Setup
The very first thing is to make a call to UseTriunniaLabsMicroservice() on the Host Builder. This sets up the logging infrastructure and other metadata.
builder.Host.UseTriunniaLabsMicroservice(EnvironmentType.Development);
Service Setup
In the main Service Composition section of your program startup, make the call to AddTriunniaLabsMicroservice() to add the Application Api. This registers the Application Api clients, the microservice context, encryption algorithms, MessagePack formatters, and http services, caching, and resilience policies. It is required by all microservices participating in the application for it is the main call that makes the framework available to the microservice.
builder.Services.AddTriunniaLabsMicroservice(builder.Configuration);
App Setup
After service composition, when building the application itself, add another call to UseTriunniaLabsMicroservice() on the Application Builder. This performs further setup functions, such enabling the ArchDependencyMiddleware, making registered MessagePack formatters available on the StaticCompositeResolver, and activating AES-GCM encryption with the Bootstrap Key if that feature is enabled.
app.UseTriunniaLabsMicroservice();
The following code can be helpful for development environments:
if (builder.Environment.IsDevelopment()) builder.Services.AddSingleton<DummyIpAddressMiddleware>();
And:
if (app.Environment.IsDevelopment()) app.UseMiddleware<DummyIpAddressMiddleware>();
Authentication Setup
Back in the Service Composition section, set up the Application Api Authentication Scheme as shown below. This authorization is required for communication between microservices within the application.
builder.services.AddAuthentication(options => options.DefaultScheme = ArchConstants.ApplicationAuthenticationScheme) .AddApplicationApiScheme();
Diagnostics Setup
Register an IDiagnosticConfigurationProvider and implement it so that you can diagnose any configuration problems.
builder.Services.AddTransient<IDiagnosticConfigurationProvider, DiagnosicConfigurationProvider>();
Formatter Setup
Any data type that would transit within Arch's protected envelope must be serializable by MessagePack. A MessagePackFormatter for all such types must exist in StaticCompositeResolver. Arch provides convenience methods for this registration in the form of:
services.AddStandardMessagePackFormatter<T>();
And:
services.AddStandardMessagePackFormatters(new[] { typeof(T1), typeof(T2), ... });
An untrusted byte array converter might also need to be added. Example:
builder.Services.AddKeyedSingleton<IByteArrayConverter<MyApp.MyType>, MessagePackUntrustedByteArrayConverter<MyApp.MyType>> ("MessagePackUntrustedByteArrayConverter<MyApp.MyType>");
See: Program.cs
Conclusion
At this point, your application is set up as an Arch application. Any incoming requests will be validated by the Application Api automatically and Arch resources are available to your application via the IMicroserviceContext and any of the clients.
Writing a Controller
When writing a controller, inherit from ArchControllerBase. This makes the MicroserviceContext easily available and provides necessary support functions for interacting with protected envelopes.
Aspire
If using Aspire, add this extension method to your solution to install the Application Api in the Aspire solution. Set the correct verison number, fill in the environment variables, ensure the bind mount path is accurate, and make any other changes as required.
public static void AddApplicationApi(this IDistributedApplicationBuilder builder, IResourceBuilder<SqlServerServerResource> sqlServer) { var applicationApiDb = sqlServer.AddDatabase("ApplicationApiDb"); var applicationApi = builder.AddContainer("ApplicationApi", "gitea.triunnialabs.com/triunnialabs/arch-application-api", "0.9.9") .WithEndpoint(50001, 8080, isProxied: false, name: "http") .WithEndpoint("http", e => e.TargetHost = "0.0.0.0") // Obtain the values for these fields from the Control Panel .WithEnvironment("Microservice__Name", "") .WithEnvironment("Microservice__EnvelopePassword", "") .WithEnvironment("Microservice__EnableDiagnostics", "true") // Set to false in production deployments .WithEnvironment("Microservice__Application__Url", "") .WithEnvironment("Microservice__Application__ApplicationId", "") .WithEnvironment("Microservice__Application__ApiKey", "") .WithEnvironment("Microservice__Application__EnvelopePassword", "") .WithEnvironment("Microservice__ProtectedMemory__HmacSha512HashKey", "") .WithEnvironment("Microservice__ProtectedMemory__AesEncryptionPassword", "") .WithEnvironment("Microservice__ProtectedMemory__AesEncryptionSalt", "") .WithEnvironment("SqlServer__ConnectionString", "") .WithEnvironment("SqlServer__ReadOnlyConnectionString", "") .WithEnvironment("YubiHsm__ConnectorUrl", "") .WithEnvironment("Guardian__AccessToken", "") .WithEnvironment("Guardian__BootstrapKeyObjectId", "") // Api will write log and other files to this relatiove source folder .WithBindMount("..\\..\\..\\data\\ApplicationApi", "/opt/triunnialabs/arch/application-api") .WithReference(applicationApiDb) .WaitFor(applicationApiDb); }
See: ApplicationApiSetup.cs
Tech Sovereignty
Arch
Company
About Contact