use singleton for helpers
This commit is contained in:
parent
86d6fdb5dd
commit
e1b74a36a0
@ -50,13 +50,14 @@ namespace COA.EnterpriseServices.DataAccess
|
||||
// load data access based on active configuration
|
||||
return Dependencies.Container
|
||||
.GetAllInstances<IDataAccess<T>>()
|
||||
.Where(i =>
|
||||
.Select(i => new
|
||||
{
|
||||
var dataAccessType = i.GetType().FullName;
|
||||
|
||||
return enabledDataAccess.ContainsKey(type.FullName) && enabledDataAccess[type.FullName].Any(a => dataAccessType.StartsWith(a));
|
||||
Instance = i,
|
||||
Type = i.GetType()
|
||||
})
|
||||
.OrderBy(i => i.GetType().Name.StartsWith("QuickBase", StringComparison.OrdinalIgnoreCase))
|
||||
.Where(i => enabledDataAccess.ContainsKey(type.FullName) && enabledDataAccess[type.FullName].Any(a => i.Type.FullName.StartsWith(a)))
|
||||
.OrderBy(i => i.Type.Name.StartsWith("QuickBase", StringComparison.OrdinalIgnoreCase))
|
||||
.Select(i => i.Instance)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using StructureMap;
|
||||
using COA.EnterpriseServices.DataAccess.Helpers;
|
||||
using StructureMap;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess
|
||||
{
|
||||
@ -18,6 +19,9 @@ namespace COA.EnterpriseServices.DataAccess
|
||||
s.WithDefaultConventions();
|
||||
s.AssembliesFromApplicationBaseDirectory();
|
||||
});
|
||||
|
||||
c.For<ClientHelper>().Singleton();
|
||||
c.For<CreditorHelper>().Singleton();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ namespace COA.EnterpriseServices.DataAccess.Helpers
|
||||
{
|
||||
public class BaseHelper<T> where T : class, IRecord
|
||||
{
|
||||
protected DataAccessManager<T> DataAccessManager { get; } = new DataAccessManager<T>();
|
||||
protected DataAccessManager<T> DataAccessManager { get; } = Dependencies.Container.GetInstance<DataAccessManager<T>>();
|
||||
|
||||
public virtual T Get(int id) => DataAccessManager.Invoke(d => d.Get(i => i.Id == id).FirstOrDefault());
|
||||
|
||||
|
@ -17,6 +17,11 @@ namespace COA.EnterpriseServices.DataAccess.Helpers
|
||||
settlementAttemptDataAccess = Dependencies.Container.GetInstance<DataAccessManager<SettlementAttempt>>();
|
||||
}
|
||||
|
||||
public CreditorHelper()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Creditor GetCreditor(int id)
|
||||
{
|
||||
return creditorDataAccess.Invoke(d => d.Get(d => d.Id == id)?.FirstOrDefault());
|
||||
|
@ -1,4 +1,5 @@
|
||||
using COA.EnterpriseServices.DataAccess.Entities;
|
||||
using COA.EnterpriseServices.DataAccess;
|
||||
using COA.EnterpriseServices.DataAccess.Entities;
|
||||
using COA.EnterpriseServices.DataAccess.Helpers;
|
||||
|
||||
namespace COA.EnterpriseServices.Sandbox
|
||||
@ -13,7 +14,7 @@ namespace COA.EnterpriseServices.Sandbox
|
||||
|
||||
private static void CreditorStuff()
|
||||
{
|
||||
var creditorHelper = new CreditorHelper();
|
||||
var creditorHelper = Dependencies.Container.GetInstance<CreditorHelper>();
|
||||
|
||||
// get single creditor
|
||||
var singleCreditor = creditorHelper.GetCreditor(1);
|
||||
@ -36,7 +37,7 @@ namespace COA.EnterpriseServices.Sandbox
|
||||
|
||||
private static void ClientStuff()
|
||||
{
|
||||
var clientHelper = new ClientHelper();
|
||||
var clientHelper = Dependencies.Container.GetInstance<ClientHelper>();
|
||||
|
||||
var newClient = new Client
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user