query about StartableFacility extension methods

9 views
Skip to first unread message

Adam Langley

unread,
Feb 3, 2011, 8:22:27 PM2/3/11
to castle-pro...@googlegroups.com
Hi Team,

I have been using the StartableFacility during the registration of my service.
My service is publicly registered as an interface, but the 'start' method belongs to the concrete type.

When I register like this:

container.Register(
                Component.For<IQueryRemoteHandler>().ImplementedBy<ServerQueryRemotingHandler>()
                .StartUsingMethod(server => (server as ServerQueryRemotingHandler).Start)
                );

You see I have to cast my service before I can get to the 'start' method

This suggestion is really just about usability: Shouldn't the generic type argument for the 'StartUsingMethod' be the 'ImplementedBy' type, not the 'For' type?
The container knows the concrete type, so it should be able to pass that to the StartUsingMethod... not the interface

What do you think?

Adam Langley
Senior Developer

+64 9 486 9010
+64 21 884400
alan...@winscribe.com
www.winscribe.com

 Please consider the environment before printing this email!

Krzysztof Koźmic

unread,
Feb 3, 2011, 8:24:14 PM2/3/11
to castle-pro...@googlegroups.com
it could be, but I'm not sure that would be possible without heavily
rebuilding the entire fluent API.

Adam Langley

unread,
Feb 3, 2011, 8:54:36 PM2/3/11
to castle-pro...@googlegroups.com
Hey Krzysztof,

Thanks - I thought that might be the case, the nature of fluent and heavily nested generics...
But thought I would ask!

Adam Langley
--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
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.

Krzysztof Koźmic

unread,
Feb 3, 2011, 8:56:25 PM2/3/11
to castle-pro...@googlegroups.com
Also remember that if you want to avoid casting you may specify the name
of the method as string.

Always a trade off

Adam Langley

unread,
Feb 3, 2011, 9:14:45 PM2/3/11
to castle-pro...@googlegroups.com
Absolutely - I figured you probably realised I wanted static checking... my main reason from moving away from configuration via Xml.

Thanks again,

Adam Langley

 Please consider the environment before printing this email!


Jason Meckley

unread,
Feb 4, 2011, 8:16:29 AM2/4/11
to castle-pro...@googlegroups.com
Why not have your object inherit IStartable? you still get static checking and you don't need to be explicit about this when registering the component.

Krzysztof Koźmic

unread,
Feb 4, 2011, 8:33:57 AM2/4/11
to castle-pro...@googlegroups.com
because we don't want to force anyone to inherit startable

Reply all
Reply to author
Forward
0 new messages