5

I've been updated to structuremap 3, and now I can't use FillAllPropertiesOfType for setter injection.

Is it deprecated, what should I use instead?

Steven
  • 166,672
  • 24
  • 332
  • 435
Bohdan
  • 1,984
  • 3
  • 20
  • 27

1 Answers1

5

I just ran into the same problem. Looks like the new way to do this is via Registry.PoliciesExpression.

public interface IInjectable
{
    string Test();
}

public class Injectable : IInjectable
{
    public string Test()
    {
        return this.GetType().ToString();
    }
}

public class InjectTarget
{

    public IInjectable Injectable
    {
        get;
        set;
    }

}

static class Program
{
    static void Main()
    {

        ObjectFactory.Configure(x =>
        {
            //Setter injection
            x.Policies.FillAllPropertiesOfType<IInjectable>().Use<Injectable>();

            //Standard registration
            x.For<IInjectable>().Use<Injectable>();
            x.For<InjectTarget>().Singleton().Use<InjectTarget>();
        });

        var test = ObjectFactory.GetInstance<InjectTarget>();

        Console.WriteLine(test.Injectable.Test()); //WindowsFormsApplication3.Injectable
    }
}
Xenolightning
  • 4,140
  • 1
  • 26
  • 34