Artur,
you need to associate the selector with your factory, much like you do
with interceptors.
HTH,
Krzysztof
On 15/04/2011 8:09 PM, Artur Grzegorzewicz wrote:
Hi,
I've been experimenting with typed factory facility (windsor 2.5.3).
The following code is not working as expected:
IWindsorContainer ioc = new WindsorContainer();
ioc.AddFacility<TypedFactoryFacility>();
ioc.Register(
Component.For<ITypedFactoryComponentSelector>().ImplementedBy<CustomTypedFactoryComponentSelector>(),
Component.For<IPrinter>().ImplementedBy<FooPrinter>().Named("FooPrinter").LifeStyle.Transient,
Component.For<IPrinter>().ImplementedBy<BarPrinter>().Named("BarPrinter").LifeStyle.Transient,
Component.For<IPrinterFactory>().AsFactory()
);
var factory = ioc.Resolve<IPrinterFactory>();
var foo = factory.GetPrinter("FooPrinter");
var bar = factory.GetPrinter("BarPrinter");
foo.Print();
bar.Print();
---
public interface IPrinterFactory
{
IPrinter GetPrinter(string name);
}
public interface IPrinter
{
void Print();
}
public class FooPrinter : IPrinter
{
public void Print()
{
Console.WriteLine("Foo");
}
}
public class BarPrinter : IPrinter
{
public void Print()
{
Console.WriteLine("Bar");
}
}
public class CustomTypedFactoryComponentSelector :
DefaultTypedFactoryComponentSelector
{
protected override string GetComponentName(MethodInfo method,
object[] arguments)
{
if (method.Name == "GetPrinter"&& arguments.Length == 1&&
arguments[0] is string)
{
return (string) arguments[0];
}
return base.GetComponentName(method, arguments);
}
}
It seems that GetComponentName is never called.
Any help will be appreciated.
Best regards
Artur
--
You received this message because you are subscribed to the Google Groups "Castle
Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en.