Using Unity and interfaces, how do I create a concrete class that implements IDisposable

Posted by Ryan ONeill on Stack Overflow See other posts from Stack Overflow or by Ryan ONeill
Published on 2010-03-11T20:57:46Z Indexed on 2010/03/11 20:59 UTC
Read the original article Hit count: 456

Filed under:
|

I have an interface (IDbAccess) for a database access class so that I can unit test it using Unity. It all works fine in Unity and now I want to make the concrete database class implement IDisposable so that it closes the db connections.

My problem is that Unity does not understand that my concrete class is disposable because the interface (IDbAccess) cannot implement another interface.

So how can I write code like this (pseudo code) so that Unity is aware that it needs to dispose the class as soon as I am done?

Using var MyDbAccessInstance = Unity.Resolve<IDbAccess>
{
}

Thanks

Ryan

© Stack Overflow or respective owner

Related posts about unity

Related posts about idisposable