Exemplo n.º 1
0
        public virtual void RegisterCommandsFromContainer()
        {
            if (!_container.IsLocked)
            {
                throw new InvalidOperationException("Container is not Locked");
            }

            var registrations       = _container.GetCurrentRegistrations();
            var registeredTypes     = registrations.Select(x => x.Registration.ImplementationType).Distinct().ToList();
            var commandHandlerTypes = registeredTypes
                                      .Where(x => x.GetCustomAttribute <DecoratorAttribute>() == null)
                                      .Where(x =>
                                             x.GetTypeInfo().IsAssignableToGenericType(typeof(ICommandHandler <,>)) ||
                                             x.GetTypeInfo().IsAssignableToGenericType(typeof(IAsyncCommandHandler <,>))).ToList();

            RegisterCommands(commandHandlerTypes);
        }