Unwanted constructor usage

16 views
Skip to first unread message

Germán Schuager

unread,
Nov 3, 2008, 11:09:23 AM11/3/08
to Castle Project Users
Hi,

I'm using the ArrayResolver that Hammet proposed here
http://hammett.castleproject.org/?p=257.

Also, I'm registering IValidatorRunner (from
Castle.Components.Validator) in the container in this way:

container.Register(

Component.For<IValidatorRegistry>().ImplementedBy<CachedValidationRegistry>(),

Component.For<IValidatorRunner>().ImplementedBy<ValidatorRunner>().LifeStyle.Transient
)

Besides this, I've some others components registered that implements
IValidationContributor (but are not registered with this service)


The problem that I'm facing is that when an IValidatorRunner is being
resolved, the ArrayResolver tries to get every IValidationContributor
from the container in order to use the constructor with the following
signature:

public ValidatorRunner(IValidationContributor[] contributors,
IValidatorRegistry registry)

but I don't really want this behaviour.
Instead, I just want it to be resolved using the constructor with this
other signature:

public ValidatorRunner(IValidatorRegistry registry)


Questions:
1. Is that Ok that ResolveAll returns components that implement
IValidationContributor but that are not registered using that service?
2. Is there any way to specify my requirement when registering
IValidatorRunner?

Germán Schuager

unread,
Nov 5, 2008, 6:02:19 AM11/5/08
to Castle Project Users
Hi, I'm following up to this post because I've been told that it was
tagged as spam.

Anyone on this?

Thanks.

On Nov 3, 1:09 pm, Germán Schuager <gschua...@gmail.com> wrote:
> Hi,
>
> I'm using the ArrayResolver that Hammet proposed herehttp://hammett.castleproject.org/?p=257.

Ayende Rahien

unread,
Nov 5, 2008, 7:50:58 AM11/5/08
to castle-pro...@googlegroups.com
Modify the array resolver to special case for this bit

Germán Schuager

unread,
Nov 5, 2008, 8:15:43 AM11/5/08
to castle-pro...@googlegroups.com
Thanks for the hint.

I've thought of that, but I didn't want to reference the Castle.Components.Validator assembly from where ArrayResolver lives.

Besides this particular problem, is it ok that ResolveAll<T> returns every component that implements T even if they are registered with another service?

Ayende Rahien

unread,
Nov 5, 2008, 8:17:33 AM11/5/08
to castle-pro...@googlegroups.com
No, it isn't okay, it should only return things that are implementing the service

Germán Schuager

unread,
Nov 5, 2008, 8:54:48 AM11/5/08
to castle-pro...@googlegroups.com
Here I send you a patch that fix this behaviour.
Regards.
resolveallfix.patch

Ayende Rahien

unread,
Nov 13, 2008, 6:25:19 PM11/13/08
to castle-pro...@googlegroups.com
This patch causes conflicts, can you regenerate?

Germán Schuager

unread,
Nov 13, 2008, 10:18:15 PM11/13/08
to castle-pro...@googlegroups.com
No problem, try with this one.
resolveallfix2.patch

Ayende Rahien

unread,
Nov 14, 2008, 9:17:31 AM11/14/08
to castle-pro...@googlegroups.com
Looking at the patch, I now have about what you are talking about.

I am afraid that this is the expected behavior for ResolveAll, You get all the components whose _service_ is assignable to the service you resolve.
I mistakenly assumed that you were talking about a case where you seen that in the impl.

To solve your original problem, you would need to modify the ArrayResolver to only use matching handlers, not assignable handlers.

Germán Schuager

unread,
Nov 14, 2008, 10:24:16 AM11/14/08
to castle-pro...@googlegroups.com
Ok, no problem, it just seemed a little counter-intuitive (to me) that Resolve<T> uses GetHandler and ResolveAll<T> uses GetAssignableHandlers.

Thanks again.

Tuna Toksöz

unread,
Nov 14, 2008, 11:19:10 AM11/14/08
to castle-pro...@googlegroups.com
I can create a patch for it, because I also believe it should be that way. Should I?
--
Tuna Toksöz

Typos included to enhance the readers attention!

Tuna Toksöz

unread,
Nov 14, 2008, 11:20:06 AM11/14/08
to castle-pro...@googlegroups.com
Ignore my previous post.

Germán Schuager

unread,
Nov 20, 2008, 8:59:45 AM11/20/08
to castle-pro...@googlegroups.com
Here I send you a patch with a test for this behaviour.
Regards.
resolvealltest.patch
Reply all
Reply to author
Forward
0 new messages