Hello World
Add Your Hello World Project
1. Create a .NET Project
Create a new ASP.NET Core project to serve as your application server and add it to the solution.
Uncomment the AddProject() line in AppHost.cs. and ensure the path correctly points to your new .csproj.
2. Install and Set Up the Client Package
Install the
TriunniaLabs.Arch.Microservice NuGet package into your project and set it up according to
Application Api Development instructions.
3. Register Microservice and Apply Configuration
In the Control Panel, create a new microservice for your project in the Hello World application and give it the
Custom Api type.
Fill in all relevant configuration details.
Grant Access to this microservice so that it is authorized.
Then copy the
appsettings.json block generated by the Control Panel into your project's appsettings.json file.
Your project will receive all the information required to communicate with Arch from that configuration.
For the URLs, if localhost doesn't work, try host.docker.internal.
4. Create Hello World Controller
Create a HelloWorldController and add the following code:
public class HelloWorldController : ArchControllerBase
{
public HelloWorldController(IMicroserviceContext microserviceContext) : base(microserviceContext)
{
}
[HttpGet]
public IActionResult HelloWorld()
{
return Ok($"Hello World from {MicroserviceContext.Settings.Name.GetDecryptedValue()");
}
}
5. Run Your Application
Press F5 from the Aspire AppHost project to start the solution.
In your browser, go to http://localhost:12345/helloworld (change the port number to what is appropriate).
You should see
Hello World from <Name> where <Name> is the name you gave to your custom microservice in the Control Panel.
You can also verify that your application authenticates successfully with the Application Api on startup.
The Control Panel's Verify Authorization diagnostic can be used to test the connection independently if you need to isolate a problem.