using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Reflection; namespace COA.EnterpriseServices.DataAccess { public interface IDataAccess where T : class, IRecord { bool Add(T item); bool Update(T item); ICollection Get(int id); 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)); //} }