StrataFrame Forum

BBS and multiple instances of the business Object

http://forum.strataframe.net/Topic17114.aspx

By Ertan Deniz - 6/16/2008

Business Object's constructor is fired X number of times when it is bound to grid with BBS. I have a BusinessObjectBase class which is base class for all BusinessObjects and implemented initialization (method) logic inside it and every Business Object has an overriden initialization method. Now, both of them are executed many times. But They must be executed only once.

How should I handle this situation ? What is the best practice ?

By Trent L. Taylor - 6/17/2008

How should I handle this situation ? What is the best practice ?

I don't understand your code, but it sounds like you just need to create a shared property (or dictionary) to test against so that your Init logic doesn't fire more than once.

By Ertan Deniz - 6/17/2008

Thanks. I think, This is the only way to follow.

Do you compare BBS and native binding source component / DataTable binding? Does BBS work well ? Is there a performance issues ?

By Trent L. Taylor - 6/17/2008

Do you compare BBS and native binding source component / DataTable binding? Does BBS work well ? Is there a performance issues ?

The performance should not be an issue whatsoever.  This is something that is commonly done (including ourselves).  The BBS i something that continues to grow and is what we use exclusively for reporting and grids.  So you wil be in good shape Wink

By Ertan Deniz - 7/8/2008

I've tried to develop a solution to init logic that fires more than once. I've defined a dictionary to store the business objects that are entering query mode (FillDataTable). I've tested the the object that it was in query mode.

After query, I've deleted the business object from the dictionary. BBS starts to ctruct the business object list. Since I've deleted the object from the dictionary, I Couldn't test the condition and my init logic runs many times.

Could I get your solution ? "Shared property or dictionary based solution".

Firstly, Constructor fires for the business object itself. After BBS starts and fired many times the same constructor ? How can I understand from where constructor is called ? (i.e BBS calls the constrctor ?) 

By Dustin Taylor - 7/8/2008

Again, without knowing the details of your code we can't give a code snippet type of answer, but what Trent was getting at with the shared property is basically this:

1) Add a shared (static) boolean property to your base business object called "InitFired" or some such which will be defaulted to False

2) In the init of your base business object, all logic should go inside of an If Test ("If Not InitFired Then ...").

3) Inside of that if test, you should set the InitFired property to True. That way, any subsequent firings of the init on the business objects will be negated (it will test on the initfired property, see that it is true, and skip all of the logic within)

The source of the problem is likely in that a new instance of the business object is created for each row in the grid. As such, each row is currently firing the init method for the business object. Using the above, any undesired inits should be bypassed. Keep in mind that you will need to reset the shared InitFired property yourself whenever appropriate (i.e. once the grid is fully populated).

Hope it helps Smile

Dustin

By Ertan Deniz - 7/8/2008

My solution is based on Dictionary (Shared). Because many objects can not share one property.

I couldn't catch the end of the action (i.e Grid populated fully or BBS translates last row)

Firstly, I want to solve this case in the base (Say Our Custom framework)

I don't want to write any code to catch the action in our forms.

Thanks for the response.

By Ertan Deniz - 7/9/2008

Any Comment ?
By Trent L. Taylor - 7/10/2008

I didn't know you were waiting for a comment.  What is your question in your current cycle on this problem?
By Ertan Deniz - 7/10/2008

The problem can not be solved with neither shared property nor shared dictionary. Because, We can not catch the end of population to reset the flag according to my knowledge. (like InitFired) 

I think this must be solved on the framework. A Shared property can be used to set to when calling "Activator.CreateInstance" and reset after the operation. Developers check this property to manage the flow. This  was the most convienent method that I've found.

 

Thanks.

By Trent L. Taylor - 7/11/2008

If I am understanding what you are saying, why couldn't you use the CurrentDataTableRefilled event (or override the On method OnCurrentDataTableRefilled) and add this logic there?