How To Use Windsor to Change a Deployed Application’s Behavior Without Touching a Single Line of Existing Code

Good patterns of development really make maintenance even easier. And since we are all doing maintenance after we write our first line of code, we really should keep maintenance concerns in mind at all times. When you do interfaced based development, it allows you to swap out behaviors without changing code that uses the interface. Now can you imagine taking that to the next level? 

Awhile back I was giving a presentation on Inversion of Control and I was asked if it were possible to set a new DLL next to an existing application in production and get that application to use the new DLL using IOC. The thought was that you wouldn’t have to worry about breaking existing code. I sat down later and learned that it’s not only possible, but actually very easy! It gives you a pretty powerful sword to wield should you ever need it.

Implementing A New Behavior Without Changing a Line of Deployed Code

Let’s say you are using Windsor Container for your IOC. So you have code in production and need to change some behavior. But you don’t have the ability to get to the source code, just the DLLs in production. You need to just make the current application just log a message instead of doing whatever the system did before. This system is a simple HR system called employee.system.

1. We create a project called employee.system.additional and reference the code that has the interface we need to implement.

referencing the DLL with the interface

2. Then we create our implementation of the interface. This is a new implementation of ICommand.  It's very simple, it just logs a message.

Command showing a message

3. After we are done, we build the new assembly and take that that DLL and place it in the same folder as the existing code.


4. Then we crack open the configuration file of the deployed system and make some changes to allow us to use the new DLL's code (the existing code doesn't even know of this new assembly).

showing the windsor config change

 5. Then we run the application.

displaying the new functionality

The functionality of the application has now changed completely based on a new DLL and a configuration change. How many lines did we change in the current application? That’s right, zip. Zero. None. Big goose egg.


Maintenance takes on a whole new meaning when you can do something like this! I’m not saying this is something you should do in a normal environment. But just knowing about it gives you options. It’s something that should be used in special situations like when you have access to a DLL but don’t have access to the source code.  This is something you can tuck away and pull out one day when you have a need for something like this.  Or similarly you could use something like Reflexil to just manipulate IL code and save modified assemblies to disk.

Posted 12-03-2009 10:56 PM by Rob Reynolds
Filed under: ,



MichaelMJ wrote re: How To Use Windsor to Change a Deployed Application’s Behavior Without Touching a Single Line of Existing Code
on 12-04-2009 10:25 AM

Isn't it a bit of a misnomer to say that you aren't editing code?  You've just moved your code specification to an XML file rather than having it in C#.  You've done it without re-compiling the system definitely.

Rob Reynolds wrote re: How To Use Windsor to Change a Deployed Application’s Behavior Without Touching a Single Line of Existing Code
on 12-04-2009 10:43 AM

@MichaelMJ: Yes, you are correct. Technically I am still editing a configuration file and that is arguably code.  

The point I am aiming for is that you could come up to an existing system and not have access to anything but the application in production and make it work differently without having to go back to the source of the existing system at all.


About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)