CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

OnAddEventHooks / OnRemoveEventHooks

rated by 0 users
Answered (Verified) This post has 1 verified answer | 1 Reply | 1 Follower

Top 25 Contributor
450 Posts
Tiago Freitas Leal posted on Sun, May 13 2012 6:47 PM

Hi Jonny

On thread http://forums.lhotka.net/forums/p/11259/52348.aspx you said

JonnyBee:

Actually, there is 2 important procedures:

  • OnAddEventHooks
  • OnRemoveEventHooks

The purpose is to make the "parent" observe events in the child object and raise own events to notify UI / listeners of chenges.
This is necessary for the

  • ChildChanged event
  • BusyChanged
  • PropertyChanged
  • ListChanged (SL)
  • CollectionChanged
  • ChildChanged

events to work as expected.

It's necessary to make UI helpers like PropertyStatus / ObjectStatus / ReadWriteAuthorization to work as expected as they hook into one or more of these events.

Not exactly sure when these made it into the framework but they do exist in Csla 3.6 and forward.

I searched everywhere and found no information on how and when to use these methods. No sample uses them (how come?), no ebook mentions them, no info on the forum.

1) I guess the UI Helpers you mention are universal (meaning not WinForms exclusive). So these should be used for all UI technologies.

2) As far as I understood, OnAddEventHooks should be used when:

  • the object is created
  • the object is fetched
  • OnDeserialized

3) When I have an EditableRoot that contains an EditableChildCollection that is made of EditableChild objects, I must use OnAddEventHooks:

  • on the EditableRoot using the EditableChildCollection property as the parameter
  • on the EditableChildCollection using the EditableChild property as the parameter

Regards

Tiago Freitas Leal, CslaGenFork (Open Source CSLA code generator)

Answered (Verified) Verified Answer

Top 10 Contributor
1,772 Posts
Answered (Verified) JonnyBee replied on Mon, May 14 2012 12:34 AM
Verified by Tiago Freitas Leal

1. The internal work that OnAddEventHooks/OnRemodeEventHooks do to make the parent object observe it's children is important to get f.ex OnChildChanged events to happen in all parents. You will normally not have to override or hook into these events nor do I recommend to expose these 2 methods to UI helpers.

2. OnAddEventHooks is called when a

  • BO is added to a Parent (BusinessListXYZBase or BusinessBase)
  • BO is deserialized (in base class OnDeserialized).

3. Again - You should NEVER call this event. This event is automatically called by CSLA as needed -  your code may use this to customize some behavior of add hooks for your own custom events.

 

Jonny Bekkum, Norway CslaContrib Coordinator

Page 1 of 1 (2 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems