tags:

views:

77

answers:

0

i have this:

SetAllProperties(x =>
                {
                 x.WithAnyTypeFromNamespace("mynamespace");
                });

And i intend to use BuildUp to get structuremap to apply this policy to a particular object.

However, because i've got the above code in my registry, won't structuremap try to do setter injection on all objects i ask it for?

How can i configure it so that the above policy only applies to a given type (or types which derive from a given type), or so that it only applies when i call build up?

Edit: It would be even better if i could simply ask structuremap to set all the properties who's types are registered with it in a single call without all this setup, is it possible? At the moment im doing it manually:

private static void injectDependencies(object obj)
{
    var properties = obj.GetType().GetProperties();
    foreach (var property in properties)
    {
     if (property.CanWrite && property.PropertyType.Namespace.StartsWith("mynamespace") && property.GetValue(obj, null) == null)
     {
      property.SetValue(obj, ObjectFactory.TryGetInstance(property.PropertyType), null);
     }
    }
}

Thanks

Andrew