コード例 #1
0
 public bool IsRegisteredWithKey(string serviceKey, Type serviceType)
 {
     if (!string.IsNullOrEmpty(serviceKey))
     {
         return(_container.IsRegisteredWithKey(serviceKey, serviceType));
     }
     else
     {
         return(_container.IsRegistered(serviceType));
     }
 }
コード例 #2
0
ファイル: CommandDispatcher.cs プロジェクト: Serfin/Crabot
        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);
            }
        }
コード例 #3
0
ファイル: Assertions.cs プロジェクト: ddd-cqrs-es/NAuthorize
 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);
 }
コード例 #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));
        }
コード例 #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));
        }
コード例 #6
0
ファイル: Assertions.cs プロジェクト: yreynhout/NAuthorize
 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);
 }
コード例 #7
0
 public bool IsRegistered <T>(object serviceKey)
 {
     return(_container.IsRegisteredWithKey <T>(serviceKey));
 }
コード例 #8
0
 public bool ContainsKey(TKey key) => _context.IsRegisteredWithKey <TValue>(key);
コード例 #9
0
 public static bool IsRegisteredWithName(this IComponentContext context, string serviceName, Type serviceType)
 {
     return(context.IsRegisteredWithKey(serviceName, serviceType));
 }
コード例 #10
0
 public static bool IsRegisteredWithName <TService>(this IComponentContext context, string serviceName)
 {
     return(context.IsRegisteredWithKey <TService>(serviceName));
 }
コード例 #11
0
 public static bool IsRegisteredWithKey <TService>(this IComponentContext context, object serviceKey)
 {
     return(context.IsRegisteredWithKey(serviceKey, typeof(TService)));
 }
コード例 #12
0
 private bool ExistsKeyService(TKey key)
 {
     return(_componentContext.IsRegisteredWithKey <T>(key));
 }