diff --git a/COA.EnterpriseServices.DataAccess.QuickBase/QuickBaseDataAccess.cs b/COA.EnterpriseServices.DataAccess.QuickBase/QuickBaseDataAccess.cs index f768e29..ec0288e 100644 --- a/COA.EnterpriseServices.DataAccess.QuickBase/QuickBaseDataAccess.cs +++ b/COA.EnterpriseServices.DataAccess.QuickBase/QuickBaseDataAccess.cs @@ -8,7 +8,7 @@ namespace COA.EnterpriseServices.DataAccess.QuickBase { public bool Add(T item) { - throw new NotImplementedException(); + return true; } public bool Update(T item) diff --git a/COA.EnterpriseServices.DataAccess/CreditorHelper.cs b/COA.EnterpriseServices.DataAccess/CreditorHelper.cs index 1d6ae34..975778b 100644 --- a/COA.EnterpriseServices.DataAccess/CreditorHelper.cs +++ b/COA.EnterpriseServices.DataAccess/CreditorHelper.cs @@ -9,7 +9,7 @@ namespace COA.EnterpriseServices.DataAccess { public Creditor GetCreditor(int id) { - + throw new NotImplementedException(); } } } diff --git a/COA.EnterpriseServices.DataAccess/IDataAccess.cs b/COA.EnterpriseServices.DataAccess/IDataAccess.cs index 2254309..03e10c7 100644 --- a/COA.EnterpriseServices.DataAccess/IDataAccess.cs +++ b/COA.EnterpriseServices.DataAccess/IDataAccess.cs @@ -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 Get(Expression> query); } + + //public class AggregateDataAccess : IDataAccess where T : class, IRecord + //{ + // private static ICollection dataAccessTypes; + + // static AggregateDataAccess() => LoadInstances(); + + // /// + // /// Invokes a method for all instances of + // /// + // /// + // /// + // /// + // protected TResult Invoke(Func, TResult> func) + // { + // var results = new List(); + + // foreach (var dataAccessType in dataAccessTypes) + // { + // var instance = Activator.CreateInstance(dataAccessType) as IDataAccess; + + // 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); + // var aggregateType = typeof(AggregateDataAccess<>); + + // // load all types except for 1) the interface itself, 2) any interface, and 3) is not implementing AggregateDataAccess + // // 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 Get(int id) => Invoke(d => d.Get(id)); + // public ICollection Get(Expression> query) => Invoke(d => d.Get(query)); + //} } diff --git a/COA.EnterpriseServices.Sandbox/COA.EnterpriseServices.Sandbox.csproj b/COA.EnterpriseServices.Sandbox/COA.EnterpriseServices.Sandbox.csproj index ddd1894..a1345e8 100644 --- a/COA.EnterpriseServices.Sandbox/COA.EnterpriseServices.Sandbox.csproj +++ b/COA.EnterpriseServices.Sandbox/COA.EnterpriseServices.Sandbox.csproj @@ -5,6 +5,10 @@ netcoreapp3.1 + + + + diff --git a/COA.EnterpriseServices.Sandbox/Program.cs b/COA.EnterpriseServices.Sandbox/Program.cs index ed5a861..d7a1d59 100644 --- a/COA.EnterpriseServices.Sandbox/Program.cs +++ b/COA.EnterpriseServices.Sandbox/Program.cs @@ -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>(); + + + } + + 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>().Add>(); + c.For>().Add>(); + + // when only SQL is needed + //c.For().Singleton().Use(); + }); } } }