progress
This commit is contained in:
parent
a2a22af7dd
commit
4ed44dc913
@ -8,7 +8,7 @@ namespace COA.EnterpriseServices.DataAccess.QuickBase
|
||||
{
|
||||
public bool Add(T item)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(T item)
|
||||
|
@ -9,7 +9,7 @@ namespace COA.EnterpriseServices.DataAccess
|
||||
{
|
||||
public Creditor GetCreditor(int id)
|
||||
{
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess
|
||||
{
|
||||
@ -14,4 +16,56 @@ namespace COA.EnterpriseServices.DataAccess
|
||||
|
||||
ICollection<T> Get(Expression<Func<T, bool>> query);
|
||||
}
|
||||
|
||||
//public class AggregateDataAccess<T> : IDataAccess<T> where T : class, IRecord
|
||||
//{
|
||||
// private static ICollection<Type> dataAccessTypes;
|
||||
|
||||
// static AggregateDataAccess() => LoadInstances();
|
||||
|
||||
// /// <summary>
|
||||
// /// Invokes a method for all instances of <typeparamref name="T"/>
|
||||
// /// </summary>
|
||||
// /// <typeparam name="TResult"></typeparam>
|
||||
// /// <param name="func"></param>
|
||||
// /// <returns></returns>
|
||||
// protected TResult Invoke<TResult>(Func<IDataAccess<T>, TResult> func)
|
||||
// {
|
||||
// var results = new List<TResult>();
|
||||
|
||||
// foreach (var dataAccessType in dataAccessTypes)
|
||||
// {
|
||||
// var instance = Activator.CreateInstance(dataAccessType) as IDataAccess<T>;
|
||||
|
||||
// results.Add(func(instance));
|
||||
// }
|
||||
|
||||
// // if the "EF" version invokes first, return that value
|
||||
// return results.FirstOrDefault(r => !r.Equals(default(T)));
|
||||
// }
|
||||
|
||||
// private static void LoadInstances()
|
||||
// {
|
||||
// if (dataAccessTypes == null)
|
||||
// {
|
||||
// var type = typeof(IDataAccess<T>);
|
||||
// var aggregateType = typeof(AggregateDataAccess<>);
|
||||
|
||||
// // load all types except for 1) the interface itself, 2) any interface, and 3) is not implementing AggregateDataAccess<T>
|
||||
// // NOTE: the "EF" version will load first, allowing for the "QuickBase" version to run last, in a separate thread if desired
|
||||
// dataAccessTypes = AppDomain.CurrentDomain
|
||||
// .GetAssemblies()
|
||||
// .Where(a => a.FullName.StartsWith("COA.EnterpriseServices.DataAccess"))
|
||||
// .SelectMany(a => a.ExportedTypes)
|
||||
// //.Where(t => type.IsAssignableFrom(t)/* && !t.IsInterface && !aggregateType.IsAssignableFrom(t)*/)
|
||||
// //.OrderBy(t => t.Name.StartsWith("QuickBase", StringComparison.OrdinalIgnoreCase))
|
||||
// .ToList();
|
||||
// }
|
||||
// }
|
||||
|
||||
// public bool Add(T item) => Invoke(d => d.Add(item));
|
||||
// public bool Update(T item) => Invoke(d => d.Update(item));
|
||||
// public ICollection<T> Get(int id) => Invoke(d => d.Get(id));
|
||||
// public ICollection<T> Get(Expression<Func<T, bool>> query) => Invoke(d => d.Get(query));
|
||||
//}
|
||||
}
|
||||
|
@ -5,6 +5,10 @@
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="structuremap" Version="4.7.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\COA.EnterpriseServices.DataAccess.EntityFramework\COA.EnterpriseServices.DataAccess.EntityFramework.csproj" />
|
||||
<ProjectReference Include="..\COA.EnterpriseServices.DataAccess.QuickBase\COA.EnterpriseServices.DataAccess.QuickBase.csproj" />
|
||||
|
@ -1,4 +1,8 @@
|
||||
using COA.EnterpriseServices.DataAccess.EntityFramework;
|
||||
using COA.EnterpriseServices.DataAccess;
|
||||
using COA.EnterpriseServices.DataAccess.EntityFramework;
|
||||
using COA.EnterpriseServices.DataAccess.EntityFramework.Entities;
|
||||
using COA.EnterpriseServices.DataAccess.QuickBase;
|
||||
using StructureMap;
|
||||
using System;
|
||||
|
||||
namespace COA.EnterpriseServices.Sandbox
|
||||
@ -7,7 +11,30 @@ namespace COA.EnterpriseServices.Sandbox
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var dataAcces = new EntityDataAccess
|
||||
var container = CreateContainer();
|
||||
|
||||
var creditorDataAccess = container.GetAllInstances<IDataAccess<Creditor>>();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static IContainer CreateContainer()
|
||||
{
|
||||
return new Container(c =>
|
||||
{
|
||||
//c.Scan(s =>
|
||||
//{
|
||||
// s.WithDefaultConventions();
|
||||
// s.AssembliesFromApplicationBaseDirectory();
|
||||
//});
|
||||
|
||||
// when saving to QuickBase is needed (as well as SQL)
|
||||
c.For<IDataAccess<Creditor>>().Add<EntityDataAccess<Creditor>>();
|
||||
c.For<IDataAccess<Creditor>>().Add<QuickBaseDataAccess<Creditor>>();
|
||||
|
||||
// when only SQL is needed
|
||||
//c.For<ISettlementAttemptDataAccess>().Singleton().Use<EfSettlementAttemptDataAccess>();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user