Fill PropertyBag from BaseController

0 views
Skip to first unread message

Flominator

unread,
Feb 10, 2009, 2:59:36 AM2/10/09
to Castle Project Users
Hi there,

is there any way to fill some fields in the PropertyBag within my
BaseController from which all of my controllers are inherited? I want
to have those feeds available in every Action of every Controller
unless I change it there.

BaseController itself inherits from SmartDispatcherController. Maybe
there is some kind of hook that is called when initializing a
controller or something?

Thanks in advance,

Flo

Ben Lovell

unread,
Feb 10, 2009, 4:39:01 AM2/10/09
to castle-pro...@googlegroups.com
Could you override the propertybag and do your stuff there? I've not got VS open in front of me so that's a question as much as an answer ;)

Lee Henson

unread,
Feb 10, 2009, 5:28:20 AM2/10/09
to castle-pro...@googlegroups.com
One choice is to use a filter.

[Filter(ExecuteWhen.BeforeAction, typeof(IPreloadBaseControllerPropertyBagFilter)]
public class BaseController {
}

public class PreloadBaseControllerPropertyBagFilter : IFilter {
    public virtual bool Perform(.....) {
        controllerContext.PropertyBag.Add("mykey", myvalue);
    }
}


2009/2/10 Ben Lovell <benjami...@gmail.com>

Jorge Barnaby Rubio

unread,
Feb 10, 2009, 4:53:14 PM2/10/09
to Castle Project Users
I do it this way:

public class BaseSiteController : ARSmartDispatcherController
{
public override void Initialize()
{
base.Initialize();

PropertyBag["siteCharset"] = "value";
}
}

Hope it helps!

yorch.

On Feb 10, 5:28 am, Lee Henson <lee.m.hen...@gmail.com> wrote:
> One choice is to use a filter.
>
> [Filter(ExecuteWhen.BeforeAction,
> typeof(IPreloadBaseControllerPropertyBagFilter)]
> public class BaseController {
>
> }
>
> public class PreloadBaseControllerPropertyBagFilter : IFilter {
>     public virtual bool Perform(.....) {
>         controllerContext.PropertyBag.Add("mykey", myvalue);
>     }
>
> }
>
> 2009/2/10 Ben Lovell <benjamin.lov...@gmail.com>
>
> > Could you override the propertybag and do your stuff there? I've not got VS
> > open in front of me so that's a question as much as an answer ;)
>

Jorge Barnaby Rubio

unread,
Feb 10, 2009, 4:28:17 PM2/10/09
to Castle Project Users
I do it this way:

public class BaseSiteController : ARSmartDispatcherController
{
public override void Initialize()
{
base.Initialize();

PropertyBag["siteCharset"] = "value";
}
}

Hope it helps!

yorch.

On Feb 10, 5:28 am, Lee Henson <lee.m.hen...@gmail.com> wrote:
> One choice is to use a filter.
>
> [Filter(ExecuteWhen.BeforeAction,
> typeof(IPreloadBaseControllerPropertyBagFilter)]
> public class BaseController {
>
> }
>
> public class PreloadBaseControllerPropertyBagFilter : IFilter {
>     public virtual bool Perform(.....) {
>         controllerContext.PropertyBag.Add("mykey", myvalue);
>     }
>
> }
>
> 2009/2/10 Ben Lovell <benjamin.lov...@gmail.com>
>
> > Could you override the propertybag and do your stuff there? I've not got VS
> > open in front of me so that's a question as much as an answer ;)
>

Flominator

unread,
Feb 16, 2009, 6:01:56 AM2/16/09
to Castle Project Users
That's exactly what I was looking for. Thank you Jorge.

On 10 Feb., 22:28, Jorge Barnaby Rubio <jorge.barn...@gmail.com>
wrote:
> I do it this way:
>
> public class BaseSiteController : ARSmartDispatcherController
> {
>     public override void Initialize()
>     {
>         base.Initialize();
>
>         PropertyBag["siteCharset"] = "value";
>     }
>
> }
>
> Hope it helps!
>
> yorch.
>
> On Feb 10, 5:28 am, Lee Henson <lee.m.hen...160@gmail.com> wrote:
>
> > One choice is to use a filter.
>
> > [Filter(ExecuteWhen.BeforeAction,
> > typeof(IPreloadBaseControllerPropertyBagFilter)]
> > public class BaseController {
>
> > }
>
> > public class PreloadBaseControllerPropertyBagFilter : IFilter {
> >     public virtual bool Perform(.....) {
> >         controllerContext.PropertyBag.Add("mykey", myvalue);
> >     }
>
> > }
>
> > 2009/2/10 Ben Lovell <benjamin.lov...162@gmail.com>
>
> > > Could you override the propertybag and do your stuff there? I've not got VS
> > > open in front of me so that's a question as much as an answer ;)
>
Reply all
Reply to author
Forward
0 new messages