请求完成后,与我的 DatabaseFactory 相关联的请求范围会释放我的数据库连接吗?
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();
}
}