How can you get castle Windsor to choose the right implantation of a interface at run time when you have multiple implementations in the container.
For example lets say i have a simple interface called IExamCalc that does calculations to work out how someone did in that exam.
No we have several implementation of this like bellow for example,
public interface IExamCalc { int CalculateMark(ExamAnswers examAnswers) } public class WritenExam : IExamCalc { public int CalculateMark(ExamAnswers examAnswers) { return 4; } } public class OralExam : IExamCalc { public int CalculateMark(ExamAnswers examAnswers) { return 8; } } public class ExamMarkService { private IExamCalc _examCalc; public ExamMarkService(IExamCalc examCalc) { _examCalc = examCalc; } public int[] CalculateExamMarks(ExamAnswers[] examAnswers) { IList<int> marks = new List<int>; foreach(ExamAnswers examanswer in examaAnswers) { marks.Add(_examCalc.CalculateMark); } } }
Say the ExamMarkService is being resloved through Windor how can i make sure that the correct implementation is injected in the constructor and is this an example of a multi-tenancy problem?
Hope that all makes sence
Colin G
As David said, you can’t, but IHandlerSelector will let you take control. Check out the tests to get an idea of how to use them: https://svn.castleproject.org/svn/castle/trunk/InversionOfControl/Castle.Windsor.Tests/HandlerSelectorsTestCase.cs
Basically, you would do something like:
and then you register it with:
This will allow you to easily deal with multi-tenency issues 🙂