BusinessListBase with Multiple BusinessBases

BusinessListBase with Multiple BusinessBases

Old forum URL: forums.lhotka.net/forums/t/3961.aspx


ataylorm posted on Thursday, November 29, 2007

Please forgive the second newbie question of the week, we are craming through the book as fast as possible, but sometimes it's easier to ask. :)

 

We need to be able to create a group of objects that may be completely different businessbase objects.  For example I need to create a group that has users, blogs, audio, and video files in it at the same time.  Call it a very dynamic playlist.  Can the CSLA do this or do we need to write some additional code?  It looks like that BusinessListBase has to be strongly typed to a single object type.

Thanks!

Andrew

JoeFallon1 replied on Thursday, November 29, 2007

Your question is not all that clear.

You should lay out the use case for wanting to put all those different things into the same collection.

There must be some logical reason for aggregating them. My first thought is to keep them all separate - but I don't have your inside knowledge.

1. You can create a base class that inherits from CSLA and then have all your BOs derive from that common class. Then in your collection refer only to the Base class as the strongly typed item. You can always down cast it in the various pages where you need to use more specific properties and methods.

2. Create an Interface with common properties and methods. Have each class implement the Interface. The collection refers to the Interface as the strongly typed item and can use any of the properties and methods of the interface. Again - you can always down cast later if needed.

Joe

 

RockfordLhotka replied on Thursday, November 29, 2007

This is the purpose behind Csla.Core.IEditableBusinessObject. BusinessListBase only requires that the child objects it contains implement this interface, and this interface is implemented by Csla.Core.BusinessBase.

If you look at the CSLA .NET Version 2.1 Handbook, I discuss how to use this interface in detail.

In short, what you do is create your own custom interface that inherits from IEditableBusinessObject, then have all your different business objects implement that custom interface. This gives all your business objects a common (non-generic) type. Then you can do this:

Public Class MyList
  Inherits BusinessListBase(Of MyList, IMyCustomInterface)

Now the collection can contain any of your business objects that implement that common interface.

Copyright (c) Marimer LLC