Using ASP.Net Core in Phoesion Glow
Tags: dotnet, csharp, cloud, microservices
Published: 2023-03-14 11:14:46

**Phoesion Glow** is a microservice development framework that offers a complete solution for creating, deploying, and managing your microservices. While **Phoesion Glow** offers a glow-native SDK for writing services, many times we need to use ASP.Net specific features or add a service that is already written in ASP.Net.

In this article, we will focus on creating Glow microservices using the ASP.Net framework.


## Prerequisites / Preparation

For developing **Phoesion Glow** services we need a **Windows machine with Visual Studio 2019/2022** and **[Phoesion Glow Blaze for Windows](https://glow-docs.phoesion.com/downloads/Downloads_Blaze.html?tabs=oses-1) installed** 


# Creating a new service
#### 1. Create a new Solution
Create a new solution using **Visual Studio** with a **Firefly ASP.NET Core Service Project** project.

![VisualStudio_Create_New_Solution_Type](https://glow-docs.phoesion.com/images/Tutorials_ASP_Hosting/Create_New_Project_Template_Selection.png)
 
> [NOTE]
> If you can't find the **Firefly ASP.NET Core Service Project** template, make sure you have **Phoesion Glow Templates** visual studio extension installed. If not you can [get it from the Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=Phoesion.phoesion-glow-vstemplates-vs2022)


#### 2. Configure new Project
Name your new project and solution :
``` dummy
Project name : Foompany.Services.MyAspService
Location : <Set your location>
Solution name : Foompany.Services
```
![VisualStudio_Create_New_Solution_Configs](https://glow-docs.phoesion.com/images/Tutorials_ASP_Hosting/Create_New_Project_Setup.png)		



# The `AspFireflyService` class
Notice that your ServiceMain class now derives from `AspFireflyService` instead of the basic `FireflyService`.
The `AspFireflyService` class provides the necessary `IServer` implementations that will hook into the **ASP.Net** framework and host the **ASP.Net** stack on top of **Phoesion Glow**.
Think of it like a replacement of **Kestrel**, that instead of handling requests from sockets, it handles request from the **Phoesion Glow** framework.



# Test your services
To test that your services are up and running open a browser and go to one of the following :
- [http://localhost/**MyCompany.Services.MyAspService**/Test/Action1](http://localhost/MyCompany.Services.MyService2/Test/Action1)
- [http://localhost:16000/**MyCompany.Services.MyAspService**/Test/Action1](http://localhost:16000/MyCompany.Services.MyService2/Test/Action1)
    


# Changing the Service name _(base path)_
As a part of the **Phoesion Glow** project, your microservice **MUST** have a service name so the **API Gateway** system can route the request to the proper service.
Like native **Firefly Services** this can be specified using the `[ServiceName("XXX")]` attribute on the `ServiceMain.cs` class. 
Change this to your desired name, for example just _MyAspService_ (without the full assembly namespace that was added by the templates)

Run the project again and test using the following :
- [http://localhost/**MyAspService**/Test/Action1](http://localhost/MyAspService/Test/Action1)
- [http://localhost:16000/**MyAspService**/Test/Action1](http://localhost:16000/MySMyAspServiceervice2/Test/Action1)



# Summary
In this article, we demonstrated how easy it is to create a new **ASP.NET** microservice that can be deployed/hosted in our **Phoesion Glow** setup. 
We can now take full advantage of **Phoesion Glow** including the out-of-the-box Mediator, API Gateway, Service-Bus and Deployment/Managing/Monitoring capabilities.

For more information, you can dive into the [documentation](https://glow-docs.phoesion.com/) and [sample repo](https://github.com/Phoesion/Glow-Samples).