Further digging into the source code and it is not the view component
that is the issue, it is wherever the context is coming from.
PropertyBag is a shortcut to context.ContextVars which I assumed was
recreated on each invocation of the component, it appears that it is
not for some reason and I struggled to follow the code well enough to
see where it came from. I have found a workaround for now (I
explicitly copy both properties into the property bag - if _answer is
null, it will clear any previous entry).
On Oct 21, 7:35 pm, "Martin Nilsson" <[EMAIL PROTECTED]> wrote:
> Registration lifestyle is Singleton by default.
> In your case it seems that you should use
>
> registration.Named(registration.ServiceType.Name).LifeStyle.Transient;
>
> On Tue, Oct 21, 2008 at 4:50 AM, Neal Blomfield <[EMAIL PROTECTED]>wrote:
>
>
>
> > Should view components be registered with an explicit lifestyle?
> > If so, what should that lifestyle be and shouldn't it be the
> > WindsorViewComponentFactory that dermines the default lifestyle?
> > If not, why am I getting state shared across separate calls to
> > Render() for the same view component?
>
> > Here is the related code and an explanation of the problem to
> > hopefully make those three questions a little clearer. I have a view
> > component defined as follows:
>
> > [ViewComponentDetails("ReviewAnswer")]
> > public class ReviewAnswerViewComponent : ViewComponent
> > {
> > private Question _question;
> > private Answer _answer;
>
> > [ViewComponentParam(Required=true)]
> > public Question Question
> > {
> > get { return _question; }
> > set { _question = value; }
> > }
>
> > [ViewComponentParam]
> > public Answer Answer
> > {
> > get { return _answer; }
> > set { _answer = value; }
> > }
>
> > public override void Render()
> > {
> > PropertyBag[ "Question" ] = _question;
> > if( _answer != null )
> > {
> > PropertyBag["Answer"] = _answer;
> > }
> > string viewName = _question.GetType().Name;
> > RenderView( "ReviewAnswer", viewName );
> > }
>
> > and my site is set up to use windsor integration via the monorail
> > facility. ViewComponents are registered using the following:
>
> > Kernel.Register(
> > AllTypes.Of<ViewComponent>()
> > .FromAssembly( webAssembly )
> > .Configure(
> > delegate( ComponentRegistration registration )
> > {
>
> > registration.Named( registration.ServiceType.Name );
> > } ) );
>
> > When using the viewcomponent inside a foreach loop, I am getting the
> > same instance each time, meaning that any state from the previous
> > execution is also present; i.e. first time _answer is not null and
> > therefore copied to the property bag, second time, the answer is null
> > and therefore is not copied to the property bag BUT the property bag
> > does contain an answer (the one from the previous execution).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---