Is there any way to use CSLA with Castle Windsor?

Is there any way to use CSLA with Castle Windsor?

Old forum URL: forums.lhotka.net/forums/t/8915.aspx


bill2010 posted on Tuesday, May 11, 2010

I know that CSLA can be used with Unity via the BuildUp method, however this does does not appear to be any equivalent capability with Castle Windsor. Has anyone figured out a way to combine these two?

JonStonecash replied on Wednesday, August 11, 2010

You can write your own version of BuildUp:

 

		public static void BuildUp(object target)
{
var type = target.GetType();
foreach (var property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
if (property.CanWrite && Container.Kernel.HasComponent(property.PropertyType))
{
var value = Container.Resolve(property.PropertyType);
try
{
property.SetValue(target, value, null);
}
catch (Exception ex)
{
var message = string.Format("Error setting property {0} on type {1}, See inner exception for more information."property.Name, type.FullName);
throw new ComponentActivatorException(message, ex);
}
}
}

}
where Container is the Castle Windsor container.

Copyright (c) Marimer LLC