在请求完成后,请求范围是否与我的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();
}
}