3
votes

Can Castle Windsor do value injection?

For example, say I have a model object for an Employee with properties I want auto-mapped to an interface describing a View for MVC.

I want a way for Employee.FirstName to be set automatically set to IEmployeeView.FirstName when my model data changes.

Right now I'm using ValueInjecter, but I'd like to drop the dependency on the assembly if Windsor can do it. (I'm already using Windsor for IoC and other AOP stuff)

2
I also wanted to comment that I only use ValueInjector for setting properties on a View's interface when data changes. It's not something that will happen when different services are located by Windsor. I can post an example of a controller if needed. - jonathanpeppers
I sometimes don't use ValueInjecter directly but have IBuilder<T> interface and implementations for it, and this all is resolved by Windsor, I use this technique here: prodinner.codeplex.com - Omu

2 Answers

4
votes

It might be possible to do it with Windsor (or any other IoC container for that matter), but IoC containers are better suited to manage services, not data containers. If you try to manage data like that you will likely fall sooner or later into the service locator trap.

A proper alternative to ValueInjecter is AutoMapper.

0
votes

You should check out MEF (http://mef.codeplex.com/). It is built into .NET 4.0.