Refactoring your plugin using a three-layer pattern
In previous recipes, we implemented our plugins in the easiest and fastest way to demonstrate specific scenarios. The purpose of this recipe is to enhance the structure of your code and turn it from a one class code behind (spaghetti code where all logic and layers are tangled in one class) to a layered code (lasagna code where each layer is separate and well defined without entanglement). The three layers we will be implementing are the entry layer (the actual plugin), the business logic, and the data access layer. We will also create a few other utility classes to increase reusability.
This recipe will be based on the first plugin we implemented in the Creating your first plugin recipe in Chapter 4,Server-Side Extensions. We will refactor it to use the inversion of control (IoC) pattern, which will facilitate unit testing. We will be able to easily swap between different DAL implementations and easily convert our core code from a plugin...