Yesterday I posted up about IoC in .NET and alluded to an issue with it working with controls (just a sub-species of component) in Windows Forms. Well, I promised I would tidy up a hack that I recently put together to work around it. Here it is, I call it SitePimp.

The great thing about creating components for others to use is that you can name them whatever the hell you like :P If you can’t stand the name by all means just change it

SitePimp is an extender provider component which when dragged onto a Form (or UserControl) will provide a property to constituant controls which allows you to site them at runtime. This allows components to call GetService(…) and have that request serviced by an upstream container.

The fact that you have to drag this component onto the design surface instead of controls being sited correctly is a horrible hack, but necessary unless you vote on this bug to get it fixed.

My next post on IoC will include some examples of how you could put IoC to good use in your applications.