How to implement Custom IoC and DI in WCSF??

Topics: Web Client Software Factory
Mar 29, 2008 at 12:24 AM
I wanted to roll out my own implementation for both IoC and DI within WCSF by gutting out the Object Builder - and for the same I wanted to know what were the main constructs and functions that I'll need to replace? Certainly, the CompositionContainer is the starting point, but where else specifically do I need to inject in, especially in the page lifecycle?

Also, for the vNext for WCSF is the team trying to abstract out the DI and IoC infrastructure - kinda like the Asp.Net MVC?
Mar 29, 2008 at 8:21 PM
I would avoid rolling your own. Check out Unity http://www.codeplex.com/unity, it may be what your looking for. The time you spend rolling your own, you could focus that time and effort in patching WCFS. I have created an Issue Tracker item asking the WCSF team to consider switching to use Unity in the future.

There are a number of IoC and DI containers already out there. i.e., Spring.NET, StructureMap, Castle Windsor. Just a suggestion.


r5 wrote:
I wanted to roll out my own implementation for both IoC and DI within WCSF by gutting out the Object Builder - and for the same I wanted to know what were the main constructs and functions that I'll need to replace? Certainly, the CompositionContainer is the starting point, but where else specifically do I need to inject in, especially in the page lifecycle?

Also, for the vNext for WCSF is the team trying to abstract out the DI and IoC infrastructure - kinda like the Asp.Net MVC?

Coordinator
Mar 29, 2008 at 8:32 PM
Edited Mar 29, 2008 at 8:32 PM
Since WCSF was not explicitly designed to have the DI/IoC container pluggable, you do have a lot of work ahead of you.
However, I do know that it is possible. I have started a proof of concept where I replaced OB and the CompositionContainer with OB2 and the UnityContainer (or at least the interface to the unity container). Ihave about 12 hours invested into it, and a bit of that was learning Unity, as this was the first project I used it on.

So far, I have module loading, DI everywhere, configuration of modules, configuration of services (sort of: the concept of "CWAB Servics" goes away, as these are just objects with a Container controlled lifetime that you get via calls to UnityContainer.Resolve<MyType>).

I still need to add authentication services, a sitemap provider, and a bit more. My goal is to get the OrderManagement RI working with the CompositeWeb-Unity framework. However, this project is done in my spare time, which means I get about 4 hours a week on it, if I am lucky. One more feature would be to hide the Unity Container behind a very simple DI interface that could be implemented for other containers, but that is low on my list.

So far, there are a LOT of breaking changes, which is understandable, since the ability to swap out containers was not designed for in the first place.

When I do get these features added, I will probably blog about it and post something here.

Michael Puleio - patterns & practices
Webhttp://msdn.microsoft.com/practices/
Bloghttp://blogs.msdn.com/mpuleio/