MvvmCross コンテナーが SQLite 接続の破棄を処理できるかどうか、またはこれをリポジトリで手動で行う必要があるかどうかを知りたいです。
SQLite 接続を手動で破棄したり閉じたりしない、次のようなコード例を見てきました。
public class ExampleRepository
{
private readonly ISQLiteConnection _connection;
public ExampleRepository(ISQLiteConnectionFactory factory)
{
_connection = factory.Create("Example.db");
_connection.CreateTable<Example>();
}
public IEnumerable<Example> All()
{
return _connection.Table<Example>().ToList();
}
}
これはより良い選択肢でしょうか?
public class ExampleRepository
{
private readonly ISQLiteConnectionFactory _factory;
public ExampleRepository(ISQLiteConnectionFactory factory)
{
_factory = factory;
}
public IEnumerable<Example> All()
{
using (var connection = _factory.Create("Example.db"))
{
connection.CreateTable<Example>();
return connection.Table<Example>().ToList();
}
}
}
リポジトリで接続が使用されるたびに、using ブロックを使用して接続を破棄する方がよいでしょうか?
または、接続の作成と破棄を続けるためのオーバーヘッドが増えます。したがって、最初の例で開いたままにする理由は?