I have an interface like
public interface IAddressProvider
{
string GetAddress(double lat, double long);
}
In my consuming class I wan
Could you not just use container.GetAllInstances
?, like so:
var address = new List();
foreach (var provider in container.GetAllInstances())
{
address.add(provider.GetAddress(lat, long));
}
Edit:
I see what you mean now. If you're using StructureMap 2.x then I would recommend looking at the Conditionally
clause. However this has been removed in version 3 in favour of creating your own builder class that should be responsible for returning the correct instance.
For example:
public class AddressProviderBuilder : IInstanceBuilder
{
private readonly IContainer container;
public AddressProviderBuilder(IContainer container)
{
this.container = container;
}
public IAddressProvider Build()
{
foreach (var provider in this.container.GetAllInstances())
{
if (provider.GetAddress(lat, long) != null)
{
return provider;
}
}
return null;
}
}