コード例 #1
0
        /// <summary>
        /// 添加命令服务
        /// </summary>
        /// <param name="services"></param>
        /// <param name="assemblies"></param>
        private static void AddCommand(this IServiceCollection services, params Assembly[] assemblies)
        {
            var  commandHandlerHelper = new CommandHandlerHelper();
            Type commandHandlerType   = typeof(ICommandHandler);

            foreach (Assembly assembly in assemblies)
            {
                foreach (Type type in assembly.GetTypes())
                {
                    if (!commandHandlerType.IsAssignableFrom(type))
                    {
                        continue;
                    }
                    if (commandHandlerHelper.TryAddCommandHandler(type))
                    {
                        services.AddTransient(type);
                    }
                }
            }
            services.AddSingleton(commandHandlerHelper);
        }
コード例 #2
0
 public CommandBusImpl(CommandHandlerHelper commandHandlerHelper, IServiceProvider serviceProvider)
 {
     _commandHandlerHelper = commandHandlerHelper;
     _serviceProvider      = serviceProvider;
 }