Previous posts in the series:
Part 9 of the original series focuses in on Constructor Injection, which is one method of doing Dependency Injection (the other is Setter Injection, which we’ll get to) The reason to use Constructor or Setter Injection is a bit subjective, but (to me) boils down to if you the paramters to be mandatory and how many parameters you have. We’re not here to debate, though, we’re here to copy Alex’s hard work….
Here’s the interface Alex defines;
And the two encoders:
Let’s check out the binsor:
Notice we didn’t specify a value for the “_encoder” parameter, so Windsor will just plug in the first one it finds. And, finally, the Program:
Running this as is, gives us:
GOWZIQ EOIME YQ KICROSOFQ?
So, what if we want to send an unencrypted message? Well, we can specify which IEncoder component to wire to our sender, like so:
See? We refer to it by the name we gave the component. Running it now, gives us:
Howzit going at Microsoft?
(I bet he’s doing great…)
Setter injection…coming up!