I know what it means but want elegant solution to this problem. For a work around solution, I can create methods with different signatures, but that won’t satisfy me.
My scenario is as below:
public interface IDomainToViewMapper<TModel, TViewModel>
{
TViewModel MapDomainToView(TModel source);
}
public interface ISiteMapper : IDomainToViewMapper<Site, ViewModelOne>,
IDomainToViewMapper<Site, ViewModelTwo>
{ }
Now when I write my main implementation class, I get member with same signature issue. I can go ahead and implement interface explicitly, but because we are injecting dependencies on the fly, I can’t cast to interface, which will again be ambiguous.
public SiteMapper : ISiteMapper
{
public ViewModelOne MapDomainToView(Site site) { ... }
public ViewModelTwo MapDomainToView(Site site) { ... }
}
Any elegant solution to the issue would be great
Your SiteMapper is basically a Factory if I understand your design, make your SiteMapper method MapDomainToView return a list of ViewModels for a given Site, add a method where you can Register ViewModels for a specific Site, store this mapping in a Dictionary for example.
Or use Castle Windsor or your favorite IoC container in stead of SiteMapper or possibly internally in SiteMapper
Example:
This is a simple IoC, if you go this route check out Castle, Unity, NInject etc