Update IoC and the "GET" function in the repository (lock issue)
This commit is contained in:
@@ -11,32 +11,31 @@ namespace skydiveLogs_api.Data
|
||||
{
|
||||
public class AircraftRepository : IAircraftRepository
|
||||
{
|
||||
public AircraftRepository(IDataProvider dataProvider)
|
||||
{
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.GetCollection<Aircraft>();
|
||||
}
|
||||
|
||||
public IEnumerable<Aircraft> GetAll()
|
||||
{
|
||||
IEnumerable<Aircraft> result = new List<Aircraft>();
|
||||
var results = _col.FindAll().ToList();
|
||||
_dataProvider.Close();
|
||||
|
||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
||||
{
|
||||
var col = db.GetCollection<Aircraft>("Aircraft");
|
||||
|
||||
result = col.FindAll().ToList();
|
||||
}
|
||||
|
||||
return result;
|
||||
return results;
|
||||
}
|
||||
|
||||
public Aircraft GetById(int id)
|
||||
{
|
||||
Aircraft result;
|
||||
|
||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
||||
{
|
||||
var col = db.GetCollection<Aircraft>("Aircraft");
|
||||
|
||||
result = col.FindById(new BsonValue(id));
|
||||
}
|
||||
var result = _col.FindById(new BsonValue(id));
|
||||
_dataProvider.Close();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly LiteCollection<Aircraft> _col;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user