public interface IFoo{} public class Foo1 : IFoo { public Foo1(int id){} public Foo1(string val){} } public class Foo2 : IFoo { public Foo2(int id){} public Foo2(string val){} }
Appropriate registry settings for this ...
ForRequestedType<IFoo>().TheDefault.Is.ConstructedBy(()=>new Foo1("some string val")); InstanceOf<IFoo>().Is.OfConcreteType<Foo2>();
then we use IFoo as a parameter for something else ... ex:
public interface IBar{} public class Bar1:IBar { public Bar1(IFoo foo){} } public class Bar2:IBar { public Bar2(IFoo foo){} }
Registration for this is next ...
ForRequestedType<IBar>().TheDefault.Is.OfConcreteType<Bar1>().CtorDependency<IFoo>().Is<Foo1>();
Now I want Bar2 to use Foo2, and I want Foo2 to use the constructor "new Foo2 (1)" I tried
InstanceOf<Foo2>().Is.ConstructedBy(()=> new Foo2(1));
but it fails. How, if at all, can I get this to work using the StructureMap registry?
source share