Minimal microservice

Before we end this chapter, I want to show you how you can avoid a lot of the code that you see in our main.cs. You will still see it throughout the book as it is important for you to understand what is going on and to learn, but abstraction is a big part of what we do. Our minimal Microservice looks as follows:

static void Main(string[] args)
{
TopshelfUtility.Run<Microservice>();
}

That's it. Some of you may prefer that you use this approach versus the verbose code that you see otherwise. This is a preference that you now have. Only you know your organization best to know what is acceptable and what is not. For your convenience, the advanced filesystem monitor and the base microservice class both have implementations of this in the code for the book, just in case you want to see how it is implemented.

The only other additional thing that you need to do is remove a lot of the code from your microservice and support a new Start method as follows:

public class Microservice : TopshelfServiceBase
protected override void Process(CancellationToken cancellationToken)
{
}
..................Content has been hidden....................

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