The Bitter Coder Tutorials Binsor Style, Part X: Setter Injection
Previous posts in the series:
We are slightly refactoring the project from Part 9, adding the ability to specify a formatter for our encoded message. The interface is here:Here’s the default formatter: And the refactored version of last post’s message sender, incorporating our new dependency: Looking at the config now, we have: Notice that we don’t specifically set the Formatter in the config, so Windsor will do that for us. Running the program now will yield the same results as the last post. Keeping with Alex’s tutorial, let’s make another formatter, this one based on the NVelocity template engine. NVelocity has changed a good bit since Alex used it in his tutorial, so the code is a bit more complex (thanks for the help on this, Alex): Our formatter merges the parameters (from, to, and body) with the template, which looks like: Finally, let’s see how we configure the program to use our fancy new formatter: We specify the template file as well as the “Formatter” parameter. Our output now looks like:
To: hammett From: email@example.com Sent: 8/25/2008 9:49:39 AM ———————-
Howzit going at Microsoft?
———————- And we’re done. We covered a decent amount of stuff in this post: setter injection, default dependencies, overriding default dependencies, as well as how to use NVelocity as a template engine.