Multiple BasedOn and WithService.Base()

103 views
Skip to first unread message

Asger Hallas

unread,
Aug 31, 2012, 10:04:54 AM8/31/12
to castle-pro...@googlegroups.com
Hi

I guess this is actually a feature request - or maybe I just don't get how to do it right.

I wonder if it would be possible to: 
Register all types based on one generic interfaces and then all types based on another generic interface - and have windsor register both generic interfaces as services for the types that implements both?

Thus having Windsor aggregate services for the component if the same type is registered with several services?


But I have not had so much luck with it :)

Can you tell me, if I need to do it otherwise - and if the feature of unioning services from multiple registrations of the same type actually could make sense?

Cheers, 
Asger

Krzysztof Kozmic

unread,
Aug 31, 2012, 5:17:48 PM8/31/12
to castle-pro...@googlegroups.com
you can do it by saying (pseudo-syntax) 

Register.BasedOn<A>.ConfigureIf<B>(Forward<B>)
Register.BasedOn<B>

-- 
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/-/6xZdNN8hHycJ.
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.

Asger Hallas

unread,
Sep 3, 2012, 4:35:40 AM9/3/12
to castle-pro...@googlegroups.com
Thanks a lot!

Unless I'm doing it wrong, it still seems like a lot of code though, when used with generic interfaces:

            container.Register(Classes.FromThisAssembly().BasedOn(typeof (CommandExecutor<>))
                                   .ConfigureIf(registration => registration.Implementation.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof (IHandleMessages<>)),
                                                registration =>
                                                {
                                                    var genericArgument = registration.Implementation.GetInterfaces()
                                                        .First(y => y.GetGenericTypeDefinition() == typeof (IHandleMessages<>))
                                                        .GetGenericArguments()[0];

                                                    registration.Forward(typeof (IHandleMessages<>).MakeGenericType(genericArgument));
                                                })
                                   .WithService.Base().LifestyleTransient(),
                               Classes.FromThisAssembly().BasedOn(typeof (IHandleMessages<>)).WithService.Base().LifestyleTransient());


Would it be meaningful to support multiple BasedOn or'ed together? Would you accept a patch?

//Asger
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.

Krzysztof Kozmic

unread,
Sep 3, 2012, 6:35:58 AM9/3/12
to castle-pro...@googlegroups.com
That could be useful

Sent from my IPad

-- 
Krzysztof Kozmic


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.

Asger Hallas

unread,
Sep 22, 2012, 6:55:23 AM9/22/12
to castle-pro...@googlegroups.com
Better late than never, right? :)

Reply all
Reply to author
Forward
0 new messages