Creating a Base Microservice and Interface

Now the fun begins. We've gotten all the details out of the way, threw a whole bunch of new terms at you, and now we're ready to get to the code. In this chapter, we are going to:

  • Create a base microservice that will hold the common functionality that all our microservices can inherit
  • This project by all other microservices
  • It will supply the interface from which all projects inherit

I will give a note of warning to everyone up front. Even though the purpose (one of the purposes) of a base class is to abstract common details and functionality, for the sake of clarity and understanding in each chapter, I am redundantly showing code that might be included in our base class as it was a part of the microservice itself, and, in some cases, it will be. I would rather provide a basis for you to quickly move forward with your own ecosystem and that means more clarity in the code for the sake of brevity, or just showing how little code we could use. As each microservice is its own entity, sometimes having redundant code in your microservice is a substitute for documentation.

Now, let's talk about base classes for just a moment. Base classes are a useful way to group objects that share a common set of functionalities. Base classes can provide a default set of functionalities, while allowing customization though extensions.

In our case, we will always provide a parameterless constructor for any microservice class. Compilers commonly add a public default constructor to classes that do not define a constructor. This can be misleading to a user of the class, if your intention is for the class not to be creatable. In our case, the Inversion of Control (IoC) container always requires a parameterless constructor, so we will have it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset