コード例 #1
0
        public TIdentity New <TIdentity>()
        {
            var tag = EventStoreIdentity.GetTagForIdentityClass(typeof(TIdentity));
            Func <long, IIdentity> factory = GetFactoryForTag(tag);

            return((TIdentity)factory(_counterService.GetNext(tag)));
        }
コード例 #2
0
        public void RegisterIdentitiesFromAssembly(Assembly assembly)
        {
            var sb = new StringBuilder();

            foreach (var ic in assembly.GetTypes().Where(x => typeof(IIdentity).IsAssignableFrom(x) && !x.IsAbstract && x.IsClass))
            {
                var tag = EventStoreIdentity.GetTagForIdentityClass(ic);

                {
                    var ctor = ic.Constructor(new Type[] { typeof(long) });
                    if (ctor == null)
                    {
                        var message = String.Format("Identity {0} must have the constructor {1}(long id)\n", ic.FullName, ic.Name);
                        Logger.Error(message);
                        sb.AppendFormat(message);
                        continue; //move to the next type, or everythign will crash.
                    }
                    var activator = FastReflectionHelper.GetActivator(ctor);

                    _longBasedFactories[tag] = (id) => (IIdentity)activator(new object[] { id });
                }
            }

            var errors = sb.ToString();

            if (!String.IsNullOrWhiteSpace(errors))
            {
                throw new JarvisFrameworkEngineException("Found identities with errors:\n" + errors);
            }
        }
コード例 #3
0
        public TIdentity New <TIdentity>()
        {
            var tag = EventStoreIdentity.GetTagForIdentityClass(typeof(TIdentity));

            Func <long, IIdentity> factory;

            if (!_longBasedFactories.TryGetValue(tag, out factory))
            {
                throw new Exception(string.Format("{0} not registered in IdentityManager", tag));
            }
            return((TIdentity)factory(_counterService.GetNext(tag)));
        }
コード例 #4
0
        public void RegisterIdentitiesFromAssembly(Assembly assembly)
        {
            var sb = new StringBuilder();

            foreach (var ic in assembly.GetTypes().Where(x => typeof(IIdentity).IsAssignableFrom(x) && !x.IsAbstract && x.IsClass))
            {
                var tag = EventStoreIdentity.GetTagForIdentityClass(ic);

                // registra la factory per string
                {
                    var ctor = ic.Constructor(new Type[] { typeof(string) });
                    if (ctor == null)
                    {
                        sb.AppendFormat("Identity {0} must have the constructor {1}(string id)\n", ic.FullName, ic.Name);
                    }
                    _stringBasedFactories[tag] = (id) => (EventStoreIdentity)ctor.CreateInstance(new object[] { id });
                }

                // registra la factory per long
                {
                    var ctor = ic.Constructor(new Type[] { typeof(long) });
                    if (ctor == null)
                    {
                        sb.AppendFormat("Identity {0} must have the constructor {1}(long id)\n", ic.FullName, ic.Name);
                    }
                    _longBasedFactories[tag] = (id) => (EventStoreIdentity)ctor.CreateInstance(new object[] { id });
                }
            }

            var errors = sb.ToString();

            if (!String.IsNullOrWhiteSpace(errors))
            {
                throw new Exception("Found identities with errors:\n" + errors);
            }
        }