Autofac wiring question - beginner

Posted by user645788 on Stack Overflow See other posts from Stack Overflow or by user645788
Published on 2011-03-05T06:47:53Z Indexed on 2011/03/06 16:10 UTC
Read the original article Hit count: 272

Filed under:

Beginners question: Given two classes: Myclass5 and Myclass6 how can one wire up following factory method (returned as Func) such that myclass5 and myclass6 instances and IMyClass that they depend on are all retrieved via autofac (assuming that these three instances are registered).

   public static MyClass4 FactoryMethod(int nu)
    {
        if (nu == 1)
            return new MyClass5(....);
        if (nu == 4)
            return new MyClass6(....);

        throw new NotImplementedException();
    }

public abstract class MyClass4
{

}

public class MyClass5 : MyClass4
{
    public MyClass5(int nu, IMyClass a)
    {

    }
}

public class MyClass6 : MyClass4
{
    public MyClass6(int nu, IMyClass a)
    {

    }
}

© Stack Overflow or respective owner

Related posts about autofac