public bool IsRegisteredWithKey(string serviceKey, Type serviceType)
 {
     if (!string.IsNullOrEmpty(serviceKey))
     {
         return(_container.IsRegisteredWithKey(serviceKey, serviceType));
     }
     else
     {
         return(_container.IsRegistered(serviceType));
     }
 }
Example #2
0
        public async Task DispatchAsync(Command command)
        {
            try
            {
                if (command.CommandName == "help" && command.Arguments.Count == 1)
                {
                    await HandleHelpCommand(command);

                    return;
                }

                var isCommandRegistered = _component.IsRegisteredWithKey <ICommandHandler>(command.CommandName);
                if (!isCommandRegistered)
                {
                    await _component.ResolveKeyed <ICommandHandler>("command-not-found")
                    .HandleAsync(command);

                    return;
                }

                var commandHandler = _component.ResolveKeyed <ICommandHandler>(command.CommandName);
                if (command.Arguments.Count != commandHandler.GetAttributeCommandArgsCount())
                {
                    await DisplayValidationResult(command.CalledFromChannel);
                }
                else
                {
                    var validationResult = await commandHandler.ValidateCommandAsync(command);

                    if (!validationResult.IsValid)
                    {
                        await DisplayValidationResult(command.CalledFromChannel,
                                                      validationResult.ErrorMessage);
                    }
                    else
                    {
                        await commandHandler.HandleAsync(command);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Error during processing command: {0} \n {1}", ex.Message, ex.StackTrace);

                await _component.ResolveKeyed <ICommandHandler>("internal-application-error")
                .HandleAsync(command);
            }
        }
Example #3
0
 static void HandleWhen(IComponentContext scope, object when)
 {
     if (!scope.IsRegisteredWithKey <IHandle <object> >(when.GetType()))
     {
         NUnit.Framework.Assert.Fail(
             "It appears you forgot to register a handler for the {0} message.",
             when.GetType().Name);
     }
     scope.ResolveKeyed <IHandle <object> >(when.GetType()).Handle(when);
 }
Example #4
0
        /// <inheritdoc />
        public override object Create(Type objectType)
        {
            if (objectType == null)
            {
                throw new ArgumentNullException(nameof(objectType));
            }

            return(_container.IsRegisteredWithKey(ContainerBuilderExtensions.ConfigurationRegistrationKey, objectType)
                                ? _container.ResolveKeyed(ContainerBuilderExtensions.ConfigurationRegistrationKey, objectType)
                                : _container.Resolve(objectType));
        }
Example #5
0
        public static object ResolveConfigurationType([NotNull] this IComponentContext container, [NotNull] Type objectType)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }
            if (objectType == null)
            {
                throw new ArgumentNullException(nameof(objectType));
            }

            return(container.IsRegisteredWithKey(ContainerBuilderExtensions.ConfigurationRegistrationKey, objectType)
                                ? container.ResolveKeyed(ContainerBuilderExtensions.ConfigurationRegistrationKey, objectType)
                                : container.Resolve(objectType));
        }
Example #6
0
 static void HandleWhen(IComponentContext scope, object when)
 {
     if (!scope.IsRegisteredWithKey<IHandle<object>>(when.GetType()))
     NUnit.Framework.Assert.Fail(
       "It appears you forgot to register a handler for the {0} message.",
       when.GetType().Name);
       scope.ResolveKeyed<IHandle<object>>(when.GetType()).Handle(when);
 }
 public bool IsRegistered <T>(object serviceKey)
 {
     return(_container.IsRegisteredWithKey <T>(serviceKey));
 }
Example #8
0
 public bool ContainsKey(TKey key) => _context.IsRegisteredWithKey <TValue>(key);
Example #9
0
 public static bool IsRegisteredWithName(this IComponentContext context, string serviceName, Type serviceType)
 {
     return(context.IsRegisteredWithKey(serviceName, serviceType));
 }
Example #10
0
 public static bool IsRegisteredWithName <TService>(this IComponentContext context, string serviceName)
 {
     return(context.IsRegisteredWithKey <TService>(serviceName));
 }
Example #11
0
 public static bool IsRegisteredWithKey <TService>(this IComponentContext context, object serviceKey)
 {
     return(context.IsRegisteredWithKey(serviceKey, typeof(TService)));
 }
Example #12
0
 private bool ExistsKeyService(TKey key)
 {
     return(_componentContext.IsRegisteredWithKey <T>(key));
 }