I have a factory method that builds objects that implement IDisposable
. Ultimately it is the callers that manage the lifetime of the created objects. This design is triggering a bunch of CA2000 errors. Is there something fundamentally incorrect in my design, does it need refactoring, or is it just getting too excited about static code analysis warnings?
The factory method
public static DisposableType BuildTheDisposableType(string param1, int param2)
{
var theDisposable = new DisposableType();
// Do some work to setup theDisposable
return theDisposable
}
A caller
using(var dt = FactoryClass.BuildTheDisposableType("data", 4))
{
// use dt
}