Skip to content

Creating the Equipment Microservice

Templates

Templates help us to get started by automatically creating the basic files required for a given type of component. To read more about templates visit Templates. Since we are going to start by creating a microservice, we will use the microservice template.

Microservice

A microservice is a small service with the following characteristics:

  • Highly maintainable and testable
  • Loosely coupled
  • Independently deployable
  • Organized around business capabilities
  • Owned by a small team

We should always keep in mind the characteristics mentioned above as guidance for our design.

Prerequisites

  • Make sure you have followed the steps to spin up the development environment correctly.
  • Make sure you have the latest version of the main branch, and that you have checked out the main branch.
  • Make sure you have the development services up and running as explained in the development environment article.

Executing the template

Open a bash compatible terminal (e.g. Git Bash) on the repository directory and navigate to the dotnet subdirectory:

Bash
cd dotnet/

Next we need to activate the console to work with the in-place dotnet installation:

Bash
source activate.sh

The prompt of the console should now be displaying the (Suite 3.0) message.

Note

Read more about activating the console here

Now we can run the command to create the new microservice:

Bash
dotnet new microservice -n Equipments --EntityName Equipment --BoundedContext Equipments
  • dotnet: the .Net CLI used to run .Net commands.
  • new: command for creating new projects.
  • microservice: the name of the template we are using.
  • -n: the name of the microservice being created.
  • --EntityName: the name of the main entity of the microservice.
  • --BoundedContext: the name of the bounded context, if the corresponding directory already exists, the microservice project is added to it, if not, it is created.

If all went well you should receive a message similar to this: The template "Template for creating microservices" was created successfully.

Opening Visual Studio

Now we can open Visual Studio and check what the template has done for us, to do so run the following:

Bash
 ./slngen.sh Equipments
  • ./slngen.sh: this script generates a solution file on the fly and opens Visual Studio. You should always use ./slngen.sh to open Visual Studio.

  • Equipments: is the name of the bounded context we want Visual Studio to be opened with. For more information about this see Solution Files.

It should look like this:

Equipment Microservice

  • ITsynch.Suite.Equipments.Application: the main project of the microservice, this is the executable project.
  • ITsynch.Suite.Equipments.Application.Contracts: this project is use to hold the classes that can be imported by other projects and services, for example, MassTransit Messages.
  • ITsynch.Suite.Equipments.Domain: this project hold our domain entities.
  • ITsynch.Suite.Equipments.Persistance: this project is in charge of configuring the persistance layer, for example, entity mappings, etc. =
  • ITsynch.Suite.Equipments.Persistance.SqlServerProvider: this project is in charge of database setup which is specific for Microsoft SQL Server.

We should now be able to right click on the ITsynch.Suite.Equipments.Application project and run it with the debugger. After a few seconds the web browser should be opened with the default GraphQL Playground.

Tip

The project generated by the template can be executed as is without need to modify anything. Feel free to run it to ensure everything is working before proceeding.