StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      


12»»

BO ConstructorExpand / Collapse
Author
Message
Posted 02/03/2006 7:14:28 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 05/25/2007 3:34:57 PM
Posts: 235, Visits: 309
Objects that inherit from MicroFour.StrataFrame.Business.BusinessLayer, i.e. BusinessObjects, have 2 overloads on the constructor. The second one takes an IContainer.

How and when is that used?
Post #515
Posted 02/06/2006 3:20:23 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 1:09:23 PM
Posts: 2,686, Visits: 1,888
The second constructor that accepts the IContainer is used when you drop a business object on a form or a user control. The IContainer that gets passed is the "components" collection on the form/user control. This constructor signature is a standard signature used by objects that inherit from Component, MarshalByValueComponent, or MarshalByRefComponent.


www.bungie.net
Post #518
Posted 02/07/2006 3:34:58 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 05/25/2007 3:34:57 PM
Posts: 235, Visits: 309
In a windows service you get some code like:
private System.ComponentModel.Container components = null;

public Service1()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();

// TODO: Add any initialization after the InitComponent call
}

would there be any point/benefit to passing 'components' to the BO constructor?
Post #520
Posted 02/07/2006 4:07:09 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 1:09:23 PM
Posts: 2,686, Visits: 1,888
Probably... if you drop a business object onto the service within the service designer, then the code generator will automatically call that method... I believe the service will cycle through it's "components" collection and Dispose() of each item when the service shuts down.


www.bungie.net
Post #522
Posted 02/08/2006 6:17:59 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 05/25/2007 3:34:57 PM
Posts: 235, Visits: 309
I'll try it.
Post #523
Posted 02/08/2006 6:25:36 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 05/25/2007 3:34:57 PM
Posts: 235, Visits: 309
Tried it...

The error says "The object that the business object has been dropped on must implement MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl.

How do I do that?
Post #524
Posted 02/08/2006 6:31:38 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 05/25/2007 3:34:57 PM
Posts: 235, Visits: 309
Tried inheriting from MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl -
got the following errors. Need documentation and/or guidance about how to implement this stuff on non-visual components.

TEST_FaxSending.Form1' does not implement interface member 'MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl.AddObjectToInitOnLoad(MicroFour.StrataFrame.UI.IInitOnFormLoad)''TEST_FaxSending.Form1' does not implement interface member 'MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl.AddBusinessObject(MicroFour.StrataFrame.Business.BusinessLayerBase)''TEST_FaxSending.Form1' does not implement interface member 'MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl.AddObjectToPreInitOnLoad(MicroFour.StrataFrame.UI.IPreInitOnFormLoad)'C:\_devel\release.90000\TEST-FaxSending\TEST-FaxSending\Form1.Designer.csTEST_FaxSending.Form1' does not implement interface member 'MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl.RemoveBusinessObject(MicroFour.StrataFrame.Business.BusinessLayerBase)'C:\_devel\release.90000\TEST-FaxSending\TEST-FaxSending\Form1.Designer.cs
Post #525
Posted 02/09/2006 10:12:58 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Yesterday @ 1:09:23 PM
Posts: 2,686, Visits: 1,888
The "components" collection is only used for user interface stuff, and the IContainerControl interface is only also only used for user interface stuff. Since the service you're creating does not have a user interface, I wouldn't worry about trying to implement the IContainerControl interface, and avoid the user of that constructor overload all together.

What I would do is within the "start" method for the service, create your SqlDataSourceItem and add it to the DataSources collection, then create your business objects. Then, within the "stop" method, call Dispose() on the business objects to ensure that resources are released.


www.bungie.net
Post #526
Posted 02/09/2006 5:48:53 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 05/25/2007 3:34:57 PM
Posts: 235, Visits: 309
I've got this code in my service:

//-- Create Business Objects
_Log = new DdmLog();
_Queue = new DdmQueue();
_Log.ParentBusinessObject = _Queue;
_Log.Navigated += new BusinessLayer.NavigatedEventHandler(_Log_Navigated);

and
_Queue.FillPendingItems();
if (_Queue.Navigate(BusinessNavigationDirection.First))
{
do
{
MessageBox.Show(_Log.DocumentTitle);
}
while (_Queue.Navigate(BusinessNavigationDirection.Next));
}
and
void _Log_Navigated(NavigatedEventArgs e)
{
_Log.FillByParentPrimaryKey(_Queue.DocumentID);
}

and
public void FillPendingItems()
{
try
{
//-- Establish locals
SqlCommand loCommand = new SqlCommand();

//-- Create the command
loCommand.CommandText = "SELECT * FROM dbo.DdmQueue ORDER BY DttmQueued DESC";
loCommand.CommandType = CommandType.Text;

//-- Execute the command
this.FillDataTable(loCommand);
}
catch (ApplicationException ex)
{
Console.WriteLine(ex.Message);
}
}

and I get this error
"An error occurred while creating a new DataLayer for the business object."

I guess I'm still lost.
Post #527