Monorail: Instantiating helpers

3 views
Skip to first unread message

Tomek Pluskiewicz

unread,
Nov 26, 2010, 4:44:45 AM11/26/10
to Castle Project Users
Hi

I have just attempted to create a small helper with access to the
current IEngineContext. So, I inherited AbstractHelper gave it one
constructor:

public QuerystringHelper(IEngineContext engineContext) :
base(engineContext) {...}

That results in [MissingMethodException: No parameterless constructor
defined for this object.] thrown in DefaultHelperFactory. "Why is
that?" I thought.

So I looked into the factory and it turns out that

ConstructorInfo constructorInfo =
helperType.GetConstructor(BindingFlags.Public, null, new Type[]
{typeof(IEngineContext)}, null);

returns null and thus DefaultHelperFactory falls back to invoking the
parameterless constructor which I don't have (and I don't want it).

This whole thing got me pretty confused. Why isn't GetConstructor
actually getting the right method? The same thing happens to the built-
in helpers when I run the GetConstructor method. On the other hand
running GetConstructor(new Type[] {typeof(IEngineContext)}) does work
as expected.

Can anyone tell me what is going on?

Regards
Tomasz

Patrick Steele

unread,
Nov 26, 2010, 12:25:24 PM11/26/10
to castle-pro...@googlegroups.com
Not sure why the factory is written the way it is, but you can get to
the IEngineContext by simply referring to CurrentContext property of
your base class (AbstractHelper).

---
Patrick Steele
http://weblogs.asp.net/psteele

> --
> 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.
>
>

Tomek Pluskiewicz

unread,
Nov 27, 2010, 4:38:08 AM11/27/10
to Castle Project Users
Thanks for replying.

Referring to CurrentContext will not work because it is only set in
that constructor, which takes IEngineContext but is never fired.
Doesn't really matter. I resorted to using the static properties on
MonoRailHttpHandlerFactory.

What I am more curious is why is Type#GetConstructor behaving the way
it does. I am sure it is by design, but still it seems odd.

Tomasz

On 26 Lis, 18:25, Patrick Steele <patrick.ste...@gmail.com> wrote:
> Not sure why the factory is written the way it is, but you can get to
> the IEngineContext by simply referring to CurrentContext property of
> your base class (AbstractHelper).
>
> ---
> Patrick Steelehttp://weblogs.asp.net/psteele
> > You received this message because you are subscribed to the Google Groups "Castle Project Users" group.> To post to this group, send email tocastle-pr...@googlegroups.com.> To unsubscribe from this group, send email tocastle-project-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages