Can I have conditional construction of classes when using IoC.Resolve ?

Posted by Corpsekicker on Stack Overflow See other posts from Stack Overflow or by Corpsekicker
Published on 2010-04-08T07:48:50Z Indexed on 2010/04/08 7:53 UTC
Read the original article Hit count: 503

I have a service class which has overloaded constructors. One constructor has 5 parameters and the other has 4.

Before I call,

var service = IoC.Resolve<IService>();

I want to do a test and based on the result of this test, resolve service using a specific constructor. In other words,

        bool testPassed = CheckCertainConditions();
        if (testPassed)
        {
            //Resolve service using 5 paramater constructor
        }
        else
        {
            //Resolve service using 4 parameter constructor
            //If I use 5 parameter constructor under these conditions I will have epic fail.
        }

Is there a way I can specify which one I want to use?

© Stack Overflow or respective owner

Related posts about ioc

Related posts about castle-windsor