StrataFrame Forum

BO's as properties

http://forum.strataframe.net/Topic2650.aspx

By Scott - 9/5/2006

I have classes setup with BO's as properties.

private MyBO _boname = null;
private MyBO boname
{
   get
   {
      if (_boname == null)
         _boname = new MyBO();
      return _boanme;
   }
}

My question is I remember reading some where in the documentation that when a BO is created thru code that the Dispose() method should be called.  Where would I be putting that call?  Should I even be doing something like this?  I have done this on some BO's that require using other BO's to complete a process, that way the helper BO's don't need to be created unless they are needed.

By StrataFrame Team - 9/6/2006

You could add a handler to the Disposed() method on the business object or just override the Dispose() method on the business object and manually call dispose on those object references if they are not null.

protected override Dispose(bool disposing)
{
    //-- Make the base call
    base.Dispose(disposing);

    //-- Make sure we're disposing
    if (disposing)
    {
        //-- Make sure we have a reference to the bo and dispose of it
        if (this._boname != null)
        { this._boname.Dispose(); }
    }
}

By Scott - 9/6/2006

Thanks for the info,  will do.