I have a factory class that decides which of four available subclasses it should instantiate and return. As you would expect, all subclasses implement the same interface:
public static class FooFactory{
     public IFoo CreateFoo(FooEnum enum){
            switch (enum)
            {
                case Foo1:
                    return new Foo1();
                case Foo2:
                    return new Foo2();
                 case Foo3:
                    return new Foo3(IBar);//has a constructor dependency on IBar
                case Foo4:
                    return new Foo4();
                 default:
                    throw new Exception("invalid foo!");
            }
     }
}
As you can see, one of the subclasses has a dependency defined in its constructor.
Some points of interest:
- We're using Spring.NET as our IoC.
- All subclasses of IFooare domain objects and therefore are not being instantiated by Spring.NET. I'd like to keep things this way if at all possible.
- The application has a hand written Data Access Layer (puke) so no ORM is in play here.
I'm trying to figure out how best to pass the IBar dependency into Foo3 from FooFactory. I get the feeling that this might be a problem best resolved via IoC but I can't quite grok how. I also want to keep FooFactory as unit testable as possible: i.e. I'd prefer not have to have dependencies on Spring.NET in my test code.
Thanks for reading.
 
     
     
    