Windsor 3.1 Typed Factory Facility / resolve by component id?

181 views
Skip to first unread message

Scott_M

unread,
Nov 7, 2012, 4:15:14 PM11/7/12
to castle-pro...@googlegroups.com
We are using the Windsor Typed Factory Facility in an attempt to resolve components by component name.

Here is our Factory interface

  public interface ILookupFormatterFactory
    {
        //Relies on windsor typed factory for implementation  

        ILookupFormatter Create(string componentId);

        void Release();
    }


Here is our registration code:
container.Register(
                Component.For<ILookupFormatter>()
                    .ImplementedBy<DefaultLookupFormatter>().LifeStyle.Transient
                    .Named("DefaultLookupFormatter") 
                );

            container.Register(
               Component.For<ILookupFormatter>()
                   .ImplementedBy<RegexLookupFormatter>().LifeStyle.Transient
                   .Named("RegexLookupFormatter") 
               );

            container.Register(
                Component.For<ILookupFormatterFactory>().LifeStyle.Transient
                .AsFactory()
            );  


When we resolve by name (factory.Create("RegexLookupFormatter") the wrong component is returned (component with DefaultLookupFormatter is returned).   What are we doing wrong?


Krzysztof Kozmic

unread,
Nov 7, 2012, 4:18:26 PM11/7/12
to castle-pro...@googlegroups.com
The default convention doesn't cover resolving by component name. You need to override it.



-- 
Krzysztof Kozmic

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-users/-/MqTulYtQkZgJ.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.

Scott McFadden

unread,
Nov 7, 2012, 4:33:37 PM11/7/12
to castle-pro...@googlegroups.com
Rats, was hoping to not have any additional Windsor dependencies.  Guess I need to go implement this one.

?
1
2
3
4
5
6
7
8
9
10
11
public class CustomTypedFactoryComponentSelector : DefaultTypedFactoryComponentSelector
{
    protected override string GetComponentName(MethodInfo method, object[] arguments)
    {
        if(method.Name == "GetById" && arguments.Length == 1 && arguments[0] is string)
        {
            return (string)arguments[0];
        }
        return base.GetComponentName(method, arguments);
    }
}

Thanks

Krzysztof Kozmic

unread,
Nov 7, 2012, 4:36:55 PM11/7/12
to castle-pro...@googlegroups.com
Yeah, something along those lines.


How is that a Windsor dependency? It's not something your code would be using but Windsor.

-- 
Krzysztof Kozmic

Reply all
Reply to author
Forward
0 new messages