Dependency Injection

This is one pattern many of us use without even realising we are using it. The premises are pretty simple.

Let’s say we are doing a sequential workflow, and that each step in the flow can be done by any among the various implementations of a particular interface. Now, we have two options – either write a controller class that loads the specific types and executes the flow (in which case we write one controller per flow) or have a configuration file that specifies the implementation at each step and the controller just go about invoking the interface. It is a no-brainer to see that the latter approach is more flexible.

In .Net, this is achieved by loading the assembly and type at runtime.

Here, IMashup is the interface and the assembly and type names are expected to come from a configuration file (or equivalent).

Leave a Reply

Your email address will not be published. Required fields are marked *