PDA

View Full Version : IoC newbie question


wombat
03-14-2005, 03:56 PM
Hello...

Sorry for my english.

Suppose I have byref classes in .Net Remoting:

class Master
{
private IDBMS _dbms; // it has SqlTransaction Inside
private Detail _detail;

public void Save()
{
// using _dbms to save Data
_detail.Save();
}
}

_dbms is a wrapper class of ADO.NET which both Master and Detail objects need it. I have problem, if I inject _dbms for both Master and Detail objects by using singleton=false, they will have two difference Ado.NET's SqlTransaction for both Master and Detail. But if singleton=true, I think it might have concurrency problem, which share same connection/transaction for every client. (I might be wrong).

Is injection not a good idea in this situation? all I can think now is to: change the calling from
_detail.Save() to _detail.Save(_dbms) and inject singleton=false to only Master. don't know if this is a good idea, any hint?

Mark Pollack
05-05-2005, 03:37 PM
Hi,

If your IDBMS implementation is using connection pooling then you certainly won't get the same connection for each usage if your implemenation is asking for a new connnection each time and not keeping a reference to the connection as a private data member. Generally speaking, if your dbms helper class is stateless and uses connections pools, then you shoul d be all right using it as singleton. This is the design behind the various database/orm template classes in spring. (both Java and .NET)

Hope this helps. Sorry I didn't see your post till now. :oops:

Cheers,
Mark