Subcalssing SF Business Objects


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K 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 (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 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 (3.4K 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 (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 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 (3.4K 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 (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 reputation)Advanced StrataFrame User (632 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 (3.4K 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...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search