BO default properties


Author
Message
Peter Jones
Peter Jones
Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi,

Is there any way of changing the 'default property values' when a new BO is created? For example the default AllowNullValuesOnNewRows is False and it may be that, in most cases, we would like that value to be True in which case it would be useful if we could have all new BO's start with a AllowNullValuesOnNewRows of True.

Cheers, Peter 

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
You can create your own BusinessLayer by subclassing the StrataFrame BusinessLayer.  The Inherits is added in the primary class and not the designer file.  The reason for this is exactly as you have described.  You can subclass our BusinessLayer and then when you create a new BO, change the inherits one time.  This will never be overwritten since the inherits statement is not in the file that gets modified by the BO Mapper.

Public Class MyBusinessLayer
    Inherits MicroFour.StrataFrame.Business.BusinessLayer

    '-- Overwrite any behavior here or change default values
End Class


Peter Jones
Peter Jones
Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi Trent,

Just getting round to creating a base BO class for our apps. All is fine except I get the error: Too many arguements in Public Sub New() in the BO that inherits from our modified BO. This happens in the New overload:

Protected Sub New(ByVal info As SerializationInfo, ByVal context As StreamingContext)
  MyBase.New(info, context)
  'This call is required by the Component Designer.
  Me.InitializeComponent()
  '-- Add the necessary handlers
  Me.AddHandlers()
End Sub

If I comment this overload out all is ok but being new to .Net/Subclassing etc I have no idea if this is ok or not. I realise this is not a StrataFrame issue and I'm not looking for a Subclassing 101 course but any insight would be appreciated.

However I do have a couple of StrataFrame specific questions.


My base BO sets default values for certain properties and a Private Sub InitializeComponent() section of code is created containing all the new property values. How do I make the BO, that inherits from my base BO, use the code in InitializeComponent so its own properties are initialised to the same values?

Part of the new code in the base BO is a generic data load. We enter a stored proc name into the "UpdateStoredProcedureName" property of the BO so we can have generic code for populating a BO when the parent form loads. The base BO for testing this approach just has the following code:

Public Class MyBO
    Inherits MicroFour.StrataFrame.Business.BusinessLayer

    Public Sub FillBO(ByVal StoredProc As String)
        If StoredProc.Length > 4 Then
            Me.FillByStoredProcedure(StoredProc)
        Else
            'TO DO - log error and inform user
        End If
    End Sub
    Protected Overrides Sub OnParentFormLoading()
        Me.FillBO(Me.UpdateStoredProcedureName)
    End Sub
End Class


However, when my test form runs it throws the error:

ApplicationException
 An error occurred while creating the main form
TargetInvocationException
 Exception has been thrown by the target of an invocation.
NotImplementedException
 The class [TMS_Test_01.BusinessObject1] must override the property 'TableName' since it derives from MicroFour.StrataFrame.Business.BusinessLayer.

Source     : MicroFour StrataFrame UI

Stack Trace:
   at MicroFour.StrataFrame.Business.BusinessLayer.get_TableName()
   at MicroFour.StrataFrame.Business.BusinessLayer.CreateInternalTable()
   at MicroFour.StrataFrame.Business.BusinessLayer.get__CurrentDataTable(Boolean IsSharedTable)
   at MicroFour.StrataFrame.Business.BusinessBindingSource.AddBOHandlers()
   at MicroFour.StrataFrame.Business.BusinessBindingSource.set_BusinessObject(BusinessLayer value)
   at TMS_Test_01.Form5.InitializeComponent() in C:\Documents and Settings\pmj\My Documents\Visual Studio 2005\Projects\TMS_Test_01\TMS_Test_01\Form5.Designer.vb:line 99
   at TMS_Test_01.Form5..ctor()
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
   at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   at MicroFour.StrataFrame.Application.StrataFrameApplication.RunApplication()

Line 99 in Form5 reads:
        Me.BusinessBindingSource1.BusinessObject = Me.BusinessObject11


I can see that TableName is an overrideable property but I have no idea what I should be doing here.

Cheers, Peter

 

 


StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Howdy, Peter,

You can have a public constructor (Public Sub New()) defined in a base class and you don't have to redefine it in the sub class.  What I would recommend doing is remove the constructors completely from your "base" bo class.  The reason for this is that you are going to be redefining them in your specific business object classes, so there's no need to have them both (and the template for a new BusinessObject includes the constructors).

On your second question, as long as the InitializeComponent() is called by all of the constructors in a class, then you can be pretty sure that it's going to be called.  The business objects are designed for the exact functionality you're describing... if you open the component designer for a business object, any property you set there will be placed within the InializeComponent() of that BO.  So, any instance of that BO that you create will have those values.

Any time you get a message that says "The class [class] must override the property 'property' because it derives from MicroFour.StrataFrame.Business.BusinessLayer" the property in question should be overriden within the partial class that is created by the BOMapper.  So, if you create a "base" class for all of your business objects, you're not going to use the BOMapper to create fields on it because it's the base class.  But since it's the base class, that's OK, because you won't be creating any instances of the base class directly; you'll just be inheriting it.  Therefore, any of your subclassed business objects will have overriden that field when the BOMapper generates their partial classes.  So, if you're getting that error, it's either because you didn't use the BOMapper on the business object, or you are trying to create an instance of your base class.

Peter Jones
Peter Jones
Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi Ben,

Thanks for the responses - question 2 ok and question 3 big mistake on my part but ok now. However regarding question 1 you commented: "...you don't have to redefine it in the sub class. What I would recommend doing is remove the constructors completely from your "base" bo class."

Actually this what we have - refer to the MyBO class code in my previous message. Even with a "base" BO class such as the example (no constructor code) we still get the same error. Am I misunderstanding your comment?

Cheers, Peter

StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Ah, I see, the problem is stemming from the way that .NET handles constructors.... if you don't define a constructor in a class, .NET defines a default constructor with no parameters for it.  So, when you call MyBase.New(info, context), your inherited class cannot see through your BO base class to the constructors within BusinessLayer because a new constructor has been defined. 

So, do this... go ahead and create the constructors in your base class, but take out all of the code except the MyBase.New(...) call and the call to InitializeComponent().  Mainly just remove your call to AddHandlers() or else the business rules and default values events will be handled twice per class (that is of course if you don't want to put any default or rules checking code in the base class... if you do, then you'll want to leave the calls to AddHandlers() so that you can check them in both places.

Peter Jones
Peter Jones
Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Thanks Ben, I'm up and running, Peter
StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Glad to hear it Smile
Peter Jones
Peter Jones
Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)Advanced StrataFrame User (520 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
Hi Ben,

I thought I had this under control but I still have a few problems that I'm working through. I just want confirmation of something you said earlier: "So, if you create a "base" class for all of your business objects, you're not going to use the BOMapper to create fields on it because it's the base class.".

Do I take this to mean that my "base" BO is just a standard Windows class, i.e. not something I create using the SF Business Object template.

Cheers, Peter

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Do I take this to mean that my "base" BO is just a standard Windows class, i.e. not something I create using the SF Business Object template.

Not unless you want to re-write the entire business layer logic, which would be a bit involed BigGrin  Actually, what Ben is referring to is you will create a standard Windows class, then inherit that class off of the MicroFour.StrataFrame.Business.BusinessLayer class.

Public Class MyBOClass
    Inherits MicroFour.StrataFrame.Business.BusinessLayer

'-- Add your logic here

End Class

Then, you can do one of two things when creating a new BO.  1.) Use the standard SF Business Object template to create your class.  Then open the class and replace the Inherits statement from the BusinessLayer to your BO class name (i.e. MyBOClass from above).  This way when you use the BO Mapper the fields will be created just as it normally would, but all of the inherited logic will remain. 2.)  You can create your own template that already has the inherits statement.

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