Пример #1
0
		private CommandHost GetCommandHost()
		{
			var dispatchers = new List<ICommandDispatcher>();
			var dispatcher = new CommandDispatcher(_locator, GetRegistry());

			dispatcher.Configure(_dispatcherSettings);

			dispatchers.Add(dispatcher);

			return new CommandHost(dispatchers);
		}
Пример #2
0
		private void extractProcessorsFromAgents()
		{
			var commandHost = new CommandHost(new ICommandDispatcher[] { });

			foreach (var agent in Composite.Agents)
			{
				var processorAttribute = agent.AgentAssembly.GetAttributeValue<LocationOfProcessorsAttribute>();

				// SELF the Where call below changes the meaning of the rest of the registration so it had to be removed
				Container.Register(
					AllTypes.FromAssembly(agent.AgentAssembly)
						// .Where(Component.IsInNamespace(processorAttribute.Namespace))
						.BasedOn(typeof(ICommandProcessor)).Configure(c => c.LifeStyle.Transient).WithService.AllInterfaces().WithService.
						Self());

				var registry = Container.Resolve<ICommandRegistry>();

				var dispatcher = new CommandDispatcher(new WindsorServiceLocator(Container), registry);

				var dispatcherSettings = new MessageDispatcherSettings();

				dispatcherSettings.InputChannel.WithDefault(CurrentSettings.InputChannel.Value);
				dispatcherSettings.InvalidChannel.WithDefault(CurrentSettings.ErrorChannel.Value);

				var processors = Container.ResolveAll(typeof(ICommandProcessor));

				foreach (var processor in processors)
				{
					dispatcherSettings.MessageProcessorTypes.Add(processor.GetType());
				}

				dispatcher.Configure(dispatcherSettings);

				commandHost.AddDispatcher(dispatcher);
			}

			Container.Register(Component.For<IHostedService>().Instance(commandHost).Forward<CommandHost>().LifeStyle.Transient);
		}