I have been using CSLA.NET for a few years now, but in my previous assignment our children were being added via a grid on the UI, and therefore the AddNewCore and OnAddNew methods were being fired by the grid. I could simply put the initialization code that I needed inside one of those methods and all was good with the world.
I have since moved to a different assignment and we have the need to do something like this:
Order.OrderDetails.Add(OrderDetail.NewOrderDetail());
What is the best way to "hook" into this process and initialize some values on the OrderDetail object AFTER it has a reference to its parent object. For example, I want to traverse up my parent tree and get the key from the Order object to set that on my child.
Thanks in advance,
David
This may not be the conventional way in the CSLA world but I have the parent BO handle the BLB's AddingNew event and provide a new child with various properties initialised.
HTH
Simon
I have this exact same scenario, but I still take (partial) advantage of AddNewCore() to do this (that's were I would be calling your equivalent of OrderDetail.NewOrderDetail())
However, I think you can override either InsertItem() or OnAddingNew() to hook into the process of the item being added to the list.
I vaguely recall difficulties with trying to supply the new object using OnAddingNew(), so I create the item in AddNewCore() and do additional property setting in InsertItem()
Copyright (c) Marimer LLC