Change ioc setting to Singleton for LiteDbProvider
This commit is contained in:
@@ -19,21 +19,14 @@ namespace skydiveLogs_api.Data
|
|||||||
|
|
||||||
public IEnumerable<Aircraft> GetAll()
|
public IEnumerable<Aircraft> GetAll()
|
||||||
{
|
{
|
||||||
var results = _col.FindAll().ToList();
|
return _col.FindAll().ToList();
|
||||||
_dataProvider.Close();
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Aircraft GetById(int id)
|
public Aircraft GetById(int id)
|
||||||
{
|
{
|
||||||
var result = _col.FindById(new BsonValue(id));
|
return _col.FindById(new BsonValue(id));
|
||||||
_dataProvider.Close();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private readonly IDataProvider _dataProvider;
|
private readonly IDataProvider _dataProvider;
|
||||||
|
|
||||||
private readonly LiteCollection<Aircraft> _col;
|
private readonly LiteCollection<Aircraft> _col;
|
||||||
|
|||||||
@@ -19,18 +19,12 @@ namespace skydiveLogs_api.Data
|
|||||||
|
|
||||||
public IEnumerable<DropZone> GetAll()
|
public IEnumerable<DropZone> GetAll()
|
||||||
{
|
{
|
||||||
var results = _col.FindAll().ToList();
|
return _col.FindAll().ToList();
|
||||||
_dataProvider.Close();
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DropZone GetById(int id)
|
public DropZone GetById(int id)
|
||||||
{
|
{
|
||||||
var result = _col.FindById(new BsonValue(id));
|
return _col.FindById(new BsonValue(id));
|
||||||
_dataProvider.Close();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IDataProvider _dataProvider;
|
private readonly IDataProvider _dataProvider;
|
||||||
|
|||||||
@@ -19,18 +19,12 @@ namespace skydiveLogs_api.Data
|
|||||||
|
|
||||||
public IEnumerable<Gear> GetAll()
|
public IEnumerable<Gear> GetAll()
|
||||||
{
|
{
|
||||||
var results = _col.FindAll().ToList();
|
return _col.FindAll().ToList();
|
||||||
_dataProvider.Close();
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gear GetById(int id)
|
public Gear GetById(int id)
|
||||||
{
|
{
|
||||||
var result = _col.FindById(new BsonValue(id));
|
return _col.FindById(new BsonValue(id));
|
||||||
_dataProvider.Close();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IDataProvider _dataProvider;
|
private readonly IDataProvider _dataProvider;
|
||||||
|
|||||||
@@ -19,18 +19,12 @@ namespace skydiveLogs_api.Data
|
|||||||
|
|
||||||
public IEnumerable<Jump> GetAll()
|
public IEnumerable<Jump> GetAll()
|
||||||
{
|
{
|
||||||
var results = _col.FindAll().ToList();
|
return _col.FindAll().ToList();
|
||||||
_dataProvider.Close();
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Jump GetById(int id)
|
public Jump GetById(int id)
|
||||||
{
|
{
|
||||||
var result = _col.FindById(new BsonValue(id));
|
return _col.FindById(new BsonValue(id));
|
||||||
_dataProvider.Close();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddJump(Jump newJump)
|
public bool AddJump(Jump newJump)
|
||||||
@@ -40,7 +34,6 @@ namespace skydiveLogs_api.Data
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
_col.Insert(newJump);
|
_col.Insert(newJump);
|
||||||
_dataProvider.Close();
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,19 +19,14 @@ namespace skydiveLogs_api.Data
|
|||||||
|
|
||||||
public IEnumerable<JumpType> GetAll()
|
public IEnumerable<JumpType> GetAll()
|
||||||
{
|
{
|
||||||
var results = _col.FindAll().ToList();
|
return _col.FindAll().ToList();
|
||||||
_dataProvider.Close();
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public JumpType GetById(int id)
|
public JumpType GetById(int id)
|
||||||
{
|
{
|
||||||
var result = _col.FindById(new BsonValue(id));
|
return _col.FindById(new BsonValue(id));
|
||||||
_dataProvider.Close();
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IDataProvider _dataProvider;
|
private readonly IDataProvider _dataProvider;
|
||||||
|
|
||||||
private readonly LiteCollection<JumpType> _col;
|
private readonly LiteCollection<JumpType> _col;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ namespace skydiveLogs_api.Ioc
|
|||||||
_services.AddScoped<Data.Interface.IGearRepository, Data.GearRepository>();
|
_services.AddScoped<Data.Interface.IGearRepository, Data.GearRepository>();
|
||||||
|
|
||||||
string connectionString = _configuration.GetConnectionString("DefaultConnection");
|
string connectionString = _configuration.GetConnectionString("DefaultConnection");
|
||||||
_services.AddScoped<Data.Interface.IDataProvider>(c => new Data.LiteDbProvider(connectionString));
|
_services.AddSingleton<Data.Interface.IDataProvider>(c => new Data.LiteDbProvider(connectionString));
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IServiceCollection _services;
|
private readonly IServiceCollection _services;
|
||||||
|
|||||||
Reference in New Issue
Block a user