Static DB Provider in ASP.NET MVC Causing Memory Leak

Posted by user364685 on Stack Overflow See other posts from Stack Overflow or by user364685
Published on 2010-06-11T15:40:00Z Indexed on 2010/06/11 15:43 UTC
Read the original article Hit count: 259

Hi, I have got an app I'm going to write in ASP.NET MVC and I want to create a DatabaseFactory object something like this:-

public class DatabaseFactory
{
    private string dbConn get { return <gets from config file>; }

    public IDatabaseTableObject GetDatabaseTable()
    {
    IDatabaseTableObject databaseTableObject = new SQLDatabaseObject(dbConn);
    return databaseTableObject;
    }
}

and this works fine, but I obviously have to instantiate the DatabaseFactory in every controller that needs it. If I made this static, so I could, in theory just call DatabaseFactory.GetDatabaseTable() it would cause a memory leak, wouldn't it?

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc