1
请求结束后请求连接到我的DatabaseFactory的作用域是否释放我的数据库连接?Ninject和连接请求范围
kernel.Bind<IDatabaseFactory>().To<DatabaseFactory<MySqlConnection>>().InRequestScope().WithConstructorArgument("connectionString", Config.Data.MySQLConnection);
public class DatabaseFactory<T> : Disposable, IDatabaseFactory where T : IDbConnection, new()
{
private readonly string _connectionString;
private IDbConnection _dataConnection;
public DatabaseFactory(string connectionString)
{
_connectionString = connectionString;
}
#region IDatabaseFactory Members
public IDbConnection Get()
{
return _dataConnection ?? (_dataConnection = new T { ConnectionString = _connectionString });
}
#endregion
protected override void DisposeCore()
{
if (_dataConnection != null)
_dataConnection.Dispose();
}
}
它通过使用InRequestScope从交似乎,它会在请求的末尾放置DBFactory。我注意到您发送的信息中有错吗? – 2012-07-12 16:00:21
是的,你是正确的,那就是你需要的rgt? – VJAI 2012-07-12 16:05:21