I would highly recommend against creating a dedicated/local/injected UnityContainer for each type like one of the posters suggested.
This can be approached in two ways.
One is by specifically defining the resolving in registration time as TylerOhlsen suggested.
This is a good solution, though if you register later both ARepository and BRepository as implementations for IRepository, you still need to deal with the fact you have two implenetations for the same interface, and if a third class will someday require an implementation of IRepository, without defining it specifically in the registration, it will get an unpredictable instance.
The second option, which is slightly safer, is registering a factory for IRepository.
The simplest example would be using a string as the key, like this:
// Create a resolver(abstract factory) for the IRepository interface type
var resolver = myContainer.Resolve<Func<IRepository>>();
// ... other code here...
// Register mappings for the IRepository interface to appropriate concrete types
myContainer.RegisterType<IRepository, ARepository>("A");
myContainer.RegisterType<IRepository, BRepository>("B");
Then in the implementation of FooController and BarController receive the func factory by injection and select the right instance.
public class FooController
{
IRepository repository;
public FooController(IService service, Func<IRepository> repositoryFactory)
{
repository = repositoryFactory("A");
}
}
You can read more about this here:
http://msdn.microsoft.com/en-us/library/ff660854%28v=pandp.20%29.aspx