Creating our Addresses service

We now have everything we need to create our actual services. Here, we will look at the Addresses service, understanding that the other services will follow the same pattern. Since we already have the data models, data access code, and routing in place, all we have to do is create our actual AddressesServer class. The AddressesServer class is as simple as this:

export class AddressesServer extends Server {
protected AddRouting(router: Router): void {
this.routingEngine.Add(GetAddressRouting, router);
this.routingEngine.Add(SaveAddressRouting, router);
}
}

We start the server like this:

new AddressesServer()
.WithCorsSupport()
.WithDatabase().Start();

The code is as easy as that. We are following a principle called Don't Repeat Yourself (DRY)  as much as possible. This simply states that you should aim to retype as little code as possible. In other words, you should try to avoid having code that does exactly the same thing scattered about your code base. Sometimes, you can't avoid it and sometimes, it doesn't make sense to go to the trouble of creating a lot of code scaffolding for a one- or two-line piece of code, but when you have large functional areas, you should definitely try to avoid having to copy and paste it into multiple parts of your code. Part of the reason for this is if you have copied and pasted code and subsequently you find a bug in it, you are going to have to fix that bug in multiple places.

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

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