Hi all,
It seems that if you resolve a component by name with the typed factory
facility, and that component doesn't exist, it will just return one of the
other components for the type you're resolving.
For example, the following program:
public interface IPerson
{
string Name { get; }
}
public class Jack : IPerson
{
public string Name { get { return "Jack"; } }
}
public class Bob : IPerson
{
public string Name { get { return "Bob"; } }
}
public interface IHumanFactory
{
IPerson GetJack();
IPerson GetBob();
IPerson GetFrank();
}
class Program
{
static void Main(string[] args)
{
var ct = new WindsorContainer();
ct.AddFacility<TypedFactoryFacility>();
ct.Register(AllTypes.FromThisAssembly().BasedOn<IPerson>().WithService.FirstInterface().Configure(x
=> x.Named(x.Implementation.Name)));
ct.Register(Component.For<IHumanFactory>().AsFactory());
var factory = ct.Resolve<IHumanFactory>();
Console.WriteLine(factory.GetBob().Name);
Console.WriteLine(factory.GetJack().Name);
Console.WriteLine(factory.GetFrank().Name);
}
}
Outputs:
Bob
Jack
Jack
This seems to be intentional behavior (changing this behavior causes the
Castle test named
Resolve_component_by_name_with_default_selector_falls_back_to_by_type_when_no_name_found
to fail), but I would rather it throw an exception or return null for
GetFrank in this example.
Thanks,
Cameron
--
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.