CSLA .NET

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

https://www.google.com/accounts/o8/id

rated by 0 users
Answered (Not Verified) This post has 0 verified answers | 3 Replies | 1 Follower

Not Ranked
2 Posts
maxg13 posted on Mon, Jun 25 2012 3:06 PM

I would like to implement Factory Pattern in CSLA. I can use an abstract base class or an interface for the abstraction. I have decided to use an abstract class, only because I have certain common functionality such as, saving to store, retrieving from store, and deletion of the record. Also, some properties that would apply to all implemented objects.

C# only allows for inheritance from one class, so I can either use BusinessBase or the abstract class. I would also like the concrete types to have their own set of business rules. How can this be done with CSLA?

If I do what I have listed below, will the rules in both the abstract class as well as the concrete class get fired?

 

 

Some code ...

Abstract class:

public class Form : BusinessBase<Form> {

   private static PropertyInfo<string> FormNameProperty = RegisterProperty<string>(c => c.FormName);

   public string FormName

   {

      get { return GetProperty(FormNameProperty); }

   }

 

   public abstract void LoadContent();

   protected override void AddBusinessRules()

   {

      // business rules that are commmon for all implementations

   }

}

 

Concrete implementation:

 

public class FormA : Form {

   private static PropertyInfo<string> FirstNameProperty = RegisterProperty<string>(c => c.FirstName);

   public string FirstName

   {

      get { return GetProperty(FirstNameProperty); }

   }

 

   public override void LoadContent(){

      // some custom code

   }

 

   protected override void AddBusinessRules()

   {

      // business rules that only apply to this class

   }

}

 

Factory:

 

public static class FormFactory{

   public static Form GetForm(string formanmae) {

      Type formType = GetFormType(formName);

      if(formType == null)

         return null;

 

      var form = Activator.CreateInstance(formType) as ReferralForm;

         return form;

   }

}

All Replies

Top 10 Contributor
9,282 Posts

To create a base class you really need to make it MyBusinessBase<T> so the real business class is

public class MyRealClass : MyBusinessBase<MyRealClass>

The way CSLA uses generics in the base classes assumes T is always the type of the real business class.

Rocky

Not Ranked
2 Posts
maxg13 replied on Tue, Jun 26 2012 8:17 AM

Rock, thanks for your reply.  How about this post?

http://forums.lhotka.net/forums/p/10711/50007.aspx

The solution provided by JonnyBee is similar to what I was looking for.  I am currently in the middle of coding that solution in my app.  Can you provide your insight on this solution?

Thanks

Top 10 Contributor
9,282 Posts

Jonny is describing exactly what I am saying, yes.

Rocky

Page 1 of 1 (4 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