We have developed several example solutions on our GitHub Examples Page at https://github.com/holomodular/ServiceBrick/tree/main/Examples. These projects contain all the source code needed to run the examples.
The DistributedDeployment example project demonstrates how to run the complete SERVICE BRICK platform in a distributed way. Each microservice is contained within their own webapp, exposed using a different port. It also includes a Client project that demonstrates how to authenticate and call various methods of each of the distributed microservices.
For reference, the default setup exposes the following services by port:
- Security - Port 7000
- Logging - Port 7001
- Cache - Port 7002
- Notification - Port 7003
Each web application project is built using our WebApp Starter project that can be obtained from our GitHub Examples page. It is a barebone, web application that has been configured with Swagger to support API versioning.
Security Microservice Startup
When starting the application, if there are no configured users with the ADMIN role, it will open a page to create an ADMIN user.
By default, the email is set to UnitTest@ServiceBrick.com and the password set to UnitTest123!@#
Just click the submit button, as this email and password are configured in the client console app. This will redirect you to the home page. Click the Swagger Link to view the exposed API services and to test calling them.
This must be done prior to running the client console application.
JWT Token-based Security Membership
Each of the distributed microservices are members of the infrastructure and we utilize JWT tokens to support this. Each web app contains a configuration setting in their appsettings.json file for the security token as well as a reference to the ServiceBrick.Security.Membership NuGet package. Make sure this is identical for all web apps.
The client project is a console application that starts up dependency injection and makes calls to the web app. As noted above, in the appsetting.json file, it has the web app configuration defined along with the email and password listed above.
Changing Storage Providers
Each of the WebApp projects includes several startup files that support all our different storage providers (database engines). Open the Program.cs in the root of the project. Inside of the ConfigureWebHostDefaults() method at the bottom of the file, change the startup file referenced to be any of the included files. Then open the appsettings.json file and change the connection strings for your selected storage provider. By default, it uses all the In-Memory providers, so any data created will be wiped out when stopping the web service.
Each of our example startup files use the same database and same storage provider. However, you can change this to mix and match any of the included different providers per microservice and each use their own database. Try it out!