I've written a class that does various modification to the contents of a SharePoint site. Inside that class, I've implemented a lazy resolved property
private SPWeb rootSite
{
get
{
if ( _site == null )
{
SPSite site = new SPSite( _url );
_site = site.OpenWeb();
}
return _site;
}
}
Both the SPSite and the SPWeb need to be disposed, and according to the Best Practices document this situation is called a Cross Method Dispose Pattern... only they don't give any actual suggestion on how to implement the dispose part of the pattern.
I opted to have my class implement IDisposable (disposing the site and web there), and have the caller access it through a using clause. Would that be according to "best practices", or should I have handled the problem differently?
Note that I come from a strict reference-counting background, so please correct me if my views on garbage disposal are a bit off.