Exemple #1
0
        static Cache()
        {
            List <Type> types = new List <Type>();

            foreach (Module module in Assembly.GetCallingAssembly().GetLoadedModules(true))
            {
                types.AddRange(module.FindTypes(IsCacheLoader, null));
            }
            foreach (Module module in Assembly.GetEntryAssembly().GetLoadedModules(true))
            {
                types.AddRange(module.FindTypes(IsCacheLoader, null));
            }
            foreach (Module module in Assembly.GetExecutingAssembly().GetLoadedModules(true))
            {
                types.AddRange(module.FindTypes(IsCacheLoader, null));
            }
            types.Sort(new TypeComparer());
            Type last = null;

            types.RemoveAll(delegate(Type t)
            {
                bool result = t == last;
                last        = t;
                return(result);
            });
            if (types.Count != 1)
            {
                throw new Exception("TODO");
            }
            methods  = (ICacheMethods <TValue>)types[0].GetConstructor(Type.EmptyTypes).Invoke(null);
            cache    = new Dictionary <string, WeakReference>();
            syncRoot = new object();
        }
Exemple #2
0
        protected AggregateRoot()
        {
            reconstituteMethodCache =
                new CachedMethodWithTypeSelectorBuilder(
                    typeof(AggregateRoot <TId>).GetMethod(nameof(AggregateRoot <TId> .GetOrCreateAndReconstituteEntity),
                                                          BindingFlags.Instance | BindingFlags.NonPublic),
                    (object[] objs) =>
            {
                var asHasIdTypes = objs[0] as IHaveSourceAndParentIdTypes;

                if (asHasIdTypes != null)
                {
                    return new[] { asHasIdTypes.SourceIdType, asHasIdTypes.ParentIdType }
                }
                ;

                throw new Exception("Should never ever happen");
            });
        }
Exemple #3
0
 static ChildEntity()
 {
     trySetChildMethodCache =
         new CachedMethodWithTypeSelectorBuilder(typeof(ChildAssigner).GetMethod(nameof(ChildAssigner.TrySetChildInParent)),
                                                 types => new[] { types[1], typeof(TId) });
 }
Exemple #4
0
 static Entity()
 {
     applyInternalMethodCache =
         new CachedMethodWithDefaultGenericBuilder(typeof(Entity).GetMethod(nameof(Entity.ApplyInternal),
                                                                            BindingFlags.Instance | BindingFlags.NonPublic));
 }