Subcalssing SF Business Objects


Author
Message
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
I want to start subclassing SF Buisness Objects (so I can imbed ny own Code in some of the methods)  and am not sure how to do this. I have successfully subclassed a few controls (TextBoxes, Lables) etc and they are working fine, so I am using a similar approcah for Buisness Objects.

I tried :  

public class KernelBO : MicroFour.StrataFrame.Business.BusinessLayer
{
}
My project compiles ok. I then created a new Business Object in the normal way , and went in manually and changed the generated code

from:
public partial class SquBO : MicroFour.StrataFrame.Business.BusinessLayer
to:
public partial class SquBO : KernelBaseSF.KernelBO


but got an error in compiling the Business Objects Project (KernelBaseSF.KernelBO does not contain a constructor that takes 2 arguments

What am I doing wrong here ?

 


Replies
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
To sub-class a BO, you are actually sub-classing the BusinessLayer as you have done. Then, you change the inherits in the BO to point to your sub-classing of the BusinessLayer.

//-- sample customized BusinessLayer
public class HelloWorldLayer : MicroFour.StrataFrame.Business.BusinessLayer
{
    public string GetGreeting()  { return "Hello World!"; }
}

//-- Change BO to inherit from this business layer.
public class HelloWorldBO : HelloWorldLayer
{
    //....
}


When doing the sub-class of BusinessLayer, you might need to explicitly implement the constructors, just calling the base constructors. 
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
I have put in constructor code when subclassing the SF buisnes object but am getting errors on Icontainer line and InitializeComponent. I basically took these snippets of code from the BuisnessObjects created ut of the Busimess Object Mapper. Not sure if I need the InitializeComponent line ??

My full Subclassing Code is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using MicroFour.StrataFrame.UI;
using MicroFour.StrataFrame.Business;
using MicroFour.StrataFrame.UI.Windows.Forms.DevEx;
using DevExpress.XtraEditors;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Runtime.Serialization;
using System.Diagnostics;
namespace KernelBaseSF
{
// 16-05-11 Subclass Business Object
public class KernelBO : MicroFour.StrataFrame.Business.BusinessLayer
{
public KernelBO()
: base()
{ InitializeComponent(); }
 
public KernelBO(Icontainer container)
: base()
{
container.Add(this);
InitializeComponent();
}
public KernelBO(SerializationInfo info, StreamingContext context)
:base(info,context)
{
InitializeComponent();
}
}



Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
You do not need the initialize component. That is specific to the actual BOs.  For an extended BusinessLayer, you'd use
something like this:

public class KernelBO : MicroFour.StrataFrame.Business.BusinessLayer
{
     public KernelBO() : base() {}

     public KernelBO(Icontainer container) : base( container ) {}

     public KernelBO(SerializationInfo info, StreamingContext context) :base( info, context ) {}

}


You would then add any specific code as needed.  For instance I did a BusinessLayer to support auditing and added event handlers to add/edit/delete events of base.

Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Greg. ve stripped out all the InitailizeComponent etc stuff and have it down to what you have suggested, but its coming up with a problem on Icontainer....type or namespace Icontainer could not be found.  I've included all the namespaces I think are required, including System.ComponentModel
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Hmmm....It's in System.ComponentModel, so not sure what your problem is.  Could you post a sample of the stripped down app?
Ger Cannoll
Ger Cannoll
Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)Advanced StrataFrame User (582 reputation)
Group: StrataFrame Users
Posts: 430, Visits: 507
Hi Greg.

I removed the line and typeed it in again......and now it compiles ok without an error .

Now I want to add in functionality  (into my Bae Class) to run code in the SetDefaultValues method of the Business Object. How do I code this in in my Base Class.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (2.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
I removed the line and typed it in again......and now it compiles ok without an error

 
Don't ya love it when that happens. I can't tell you how many hours I've wasted on things like this.....  Crazy

As to having custom code for SetDefaultValues, you would override the OnSetDefaultValues method.  You'll want to call the base method to ensure that the event gets raised for others to consume.

//-- In your base class....
protected override void OnSetDefaultValues()
{
    //-- Call base method to actually raise event for other consumers.
    base.OnSetDefaultValues();

    //-- Add you customization code.
}


Depending on your needs, you can call the base class first (as shown) which will raise the event, then execute your custom code (i.e. you want any other work to be done before you do yours) OR you can call it afterwards, meaning you want to have your custom work done before the event is raised and thus available to any consumers of the event.
Edited 13 Years Ago by Greg McGuffey
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Ger Cannoll - 13 Years Ago
Sam Tenney - 13 Years Ago
Terry Bottorff - 13 Years Ago
Ger Cannoll - 13 Years Ago
                     That is exactly the one it is. So no need to send it. Sorry.
Terry Bottorff - 13 Years Ago
                         Hi Terry I have had another look at the artcile and it seems to...
Ger Cannoll - 13 Years Ago
                             The error you are getting is likely because your base class and...
Greg McGuffey - 13 Years Ago
                                 Hi Greg. If subclassing the SF Business Objects is not the way to...
Ger Cannoll - 13 Years Ago
                                     You're headed in the right direction. You DO want to sub class...
Greg McGuffey - 13 Years Ago
                                         Ok Greg, still not clear on what I have to do to SubClass the SF BO....
Ger Cannoll - 13 Years Ago
                                             To sub-class a BO, you are actually sub-classing the BusinessLayer as...
Greg McGuffey - 13 Years Ago
                                                 I have put in constructor code when subclassing the SF buisnes object...
Ger Cannoll - 13 Years Ago
                                                     You do not need the initialize component. That is specific to the...
Greg McGuffey - 13 Years Ago
                                                         Hi Greg. ve stripped out all the InitailizeComponent etc stuff and...
Ger Cannoll - 13 Years Ago
                                                             Hmmm....It's in System.ComponentModel, so not sure what your problem...
Greg McGuffey - 13 Years Ago
                                                                 Hi Greg. I removed the line and typeed it in again......and now it...
Ger Cannoll - 13 Years Ago
                                                                     [quote] I removed the line and typed it in again......and now it...
Greg McGuffey - 13 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search