Hi, I have a scenario where I have multiple classes implementing one interface. When at runtime the resolution is done I want some rules to execute to give me back the required instance.
I am thinking of writing some extension for Unity which can accept the configurations like this:
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<!--Interfaces-->
<alias alias="IAddress" type="Interfaces.IAddress, Interfaces" />
<alias alias="IUnityRule" type="Interfaces.IUnityRule, Interfaces"/>
<!-- Implementations-->
<alias alias="PersonalAddress" type="Implementation.PersonalAddress, Implementation" />
<alias alias="CorrespondenceAddress" type="Implementation.CorrespondenceAddress, Implementation" />
<alias alias="AddressRule" type="Implementation.AddressRule, Implementation" />
<container>
<register type="IUnityRule" mapTo="AddressRule" name="addressRule1">
<constructor>
<param name="postcode" value="AA11AA"/>
</constructor>
</register>
<register type="IUnityRule" mapTo="AddressRule" name="addressRule2">
<constructor>
<param name="postcode" value="XX11XX"/>
</constructor>
</register>
<register type="IAddress" mapTo="PersonalAddress" name="padd">
<rule evaluate="AddressRule">
<dependency name="addressRule1"/>
</rule>
</register>
<register type="IAddress" mapTo="CorrespondenceAddress" name="cadd">
<rule evaluate="AddressRule">
<dependency name="addressRule1"/>
</rule>
</register>
</container>
</unity>
IUnityRule is
public interface IUnityRule
{
bool Evaluate()
}
I am sure that somebody else already must have faced such situation or found the solution! solutions/suggestions are greatly appreciated