Generic and Inheriting from BusinessBase<T>

Generic and Inheriting from BusinessBase<T>

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


William posted on Sunday, November 12, 2006

It is recommended to create our own base class for each business object type supported in CSLA.
 
My first attempt would be,
 
public abstract class MyBusinessBase<T> : BusinessBase<MyBusinessBase<T>>
{ ... }
 
public class Customer : MyBusinessBase<Customer>
{ ... }
 
In this case, BusinessBase takes MyBusinessBase<T> as my business object type and generates the Save method as follows, which the return type is not the target business object type.
 
public MyBusinessBase<T> BusinessBase<T>.Save() { ... }
 
I change the generic inheritance to:
 
public abstract class MyBusinessBase<T>
: BusinessBase<T> where T : MyBusinessBase<T>
{ ... }
 
In this version, the Save method from BusinessBase is generated as follows, which is correct in syntax.
 
public T BusinessBase<T>.Save() { ... }
 
Is this the correct way to use generic inheritance for CSLA classes?
 
 
Regards,
William

david.wendelken replied on Monday, November 13, 2006

There are already several threads that cover this.  You might want to do a search for them.

Alternatively, take a look at RuleBusinessBase and RuleBusinessListBase in the CSLA Contrib project.  They subclass BusinessBase and BusinessListBase.

Copyright (c) Marimer LLC