As a drummer, Chris Adler of Lamb of God has always been an idol of mine (his signature sticks are my go to), and I’ve been a huge Lamb of God Fan for a number of years now. The story of their front man, Randy Blythe getting arrested on Manslaughter charges on landing in Prague Airport, Czech Republic two years after the alleged incident was truly shocking. His book, Dark Days, recounts the ordeal and offers an insight into his incredibly strong outlook on life and how he made it through the other side.
There’s a famous quote in the world of Software Development:
“We can solve any problem by introducing an extra level of indirection.”
In my experience, this is almost certainly correct, this post will see us adding in an additional layer of Abstraction to allow us to simplify our Controller(s) and manage our Dependencies in a more straightforward manner.
Last post saw us implement our Translation PCL into our Web API using Dependency Injection. The problem is that our ITranslator Interface only handles a single Translator Implementation, such that when we inject from our Container we can’t currently translate more than one direction. We’ll look into the why’s shortly, but by the end of the post we will have created :
- ITranslatorService Interface;
- TranslatorService Implementation and Unit Tests.
Portable Class Libraries afford great benefit when it comes to sharing code across platforms/usages. We can share a single library across our UWP App where it’ll run locally and on our Web API where it’ll execute behind our endpoint. Dependency Injection has been made very accessible with the latest ASP.NET MVC Web API.
The current MorseCoder.PCL targets only Windows 8.1 as it’s point of API Reference. We’ll need to change that to extend it to the wider .NET Framework (we’re not doing anything prohibitive, so this isn’t a problem). By the end of the post we’ll have updated our PCL to target what we require, and integrated it into the Web API Project using Dependency Injection to pull in an instance of our Translator from the IServiceCollection container.
ASP.Net MVC Web API provides a straight forward controller based approach to creating RESTful HTTP based web services. It should be quite familiar to anyone with an ASP.NET MVC background. This tutorial won’t be focussing on what is and what is not RESTful, (there’s plenty of that already, and can get a little religious!).
By the end of this post we’ll have created an ASP.Net MVC 5 Web API Project, and a new Controller ready for implementation.