I would like to configure Castle Windsor to create two components of same type (Foo -> IFoo), but with different constructor inputs. I would also later like to consume both components when creating another component (type Bar - see code below).
public interface IFoo { }
public class Foo : IFoo
{
private string _prop;
public Foo(string prop)
{
_prop = prop;
}
}
public class Bar
{
private IFoo _fooAbc;
private IFoo _foo123;
public Bar(IFoo fooAbc, IFoo foo123)
{
_foo123 = foo123;
_fooAbc = fooAbc;
}
}
In component installer I tried registering components like this:
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Classes.FromThisAssembly()
.BasedOn<IFoo>().WithServiceBase()
.ConfigureFor<Foo>(c => c.DependsOn(Dependency.OnValue<string>("abc")).Named("fooAbc"))
.ConfigureFor<Foo>(c => c.DependsOn(Dependency.OnValue<string>("123")).Named("foo123")));
container.Register(Component.For<Bar>()); //?? specify which service to use
}
But castle throws an registration exception. So how can I configure two instances of Foo, one with "abc" and another with "123" dependency? Also I would later like to correctly assign them when constructing Bar, so that fooAbc is used as first constructor input, and foo123 as second. My end goal would be to successfully resolve Bar.