Controller

The next area of responsibility is the controller. This is where the execution configuration takes place with abstraction behind an interface. It can also be where you perform the setup for dependency injection (or inversion of control) if you're using a language and framework that might require that, and are following that type of design pattern. An example is Java with Spring or Dagger, or injecting mocks for testing. It's worth noting that there is also no business logic that occurs at this layer. This layer is especially good for enabling unit testing because we can inject mocks or use stubs of dependencies. 

Before we move on, let's dig into some of the benefits of running dependency injection:

  • Decouples the complexities of the execution from the implementation.
  • Because it's decoupled, it enables more flexibility, so you can easily change the implementation.
  • Greater separation: Each layer or component has its own job to do.
  • Increased testability: Can inject stubs or mocks to enable unit testing.

However, watch out for the following:

  • Injecting too many dependencies: Heavyweight frameworks such as Spring are not suitable for a Lambda container life cycle. All of your dependencies have to be included in your deployment package, which should be as small as possible.
  • Inversion of control doesn't solve things that aren't broken.
  • It adds complexity to reduce complexity – there's a balance there somewhere! 

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

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