NES- 命令不发送到 CommandHandler

NES- Command doesn't send to CommandHandler

我的命令Class如下:

public class RegisterToConference : ICommand
    {
        public RegisterToConference()
        {
            this.Id = Guid.NewGuid();
            this.Seats = new Collection<SeatQuantity>();
        }

        public Guid Id { get; set; }

        public Guid OrderId { get; set; }

        public Guid ConferenceId { get; set; }

        public ICollection<SeatQuantity> Seats { get; set; }          
    }

我的命令处理程序class如下:

public class OrderCommandHandler :
        IHandleMessages<RegisterToConference>
    {
        private readonly IRepository repository;
        private readonly IPricingService pricingService;

        public OrderCommandHandler(IRepository repository, IPricingService pricingService)
        {
            this.repository = repository;
            this.pricingService = pricingService;
        }

        public void Handle(RegisterToConference command)
        {
            var items = command.Seats.Select(t => new OrderItem(t.SeatType, t.Quantity)).ToList();
            var order = repository.Get<Registration.Order>(command.OrderId);
            if (order == null)
            {
                order = new Registration.Order(command.OrderId, command.ConferenceId, items, pricingService);
            }
            else
            {
                order.UpdateSeats(items, pricingService);
            }

            repository.Add<Registration.Order>(order);
        }

    }

我从控制器的操作方法向总线发送命令,如下所示:

this.commandBus.Send(command);

端点配置如下:

public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantToRunWhenBusStartsAndStops, IWantToRunWhenConfigurationIsComplete
    {
        public void Init()
        {
            LogManager.Use<Log4NetFactory>();
        }

        public void Start()
        {
            Wireup.Init()
                .UsingInMemoryPersistence()
                .EnlistInAmbientTransaction()
                .NES()
                .Build();
        }

        public void Stop()
        {
        }

        public void Customize(BusConfiguration configuration)
        {
            configuration.UseSerialization<Json>();
            configuration.EnableInstallers();
            configuration.UsePersistence<InMemoryPersistence>();
            configuration.UseTransport<MsmqTransport>();
            configuration.PurgeOnStartup(false);
            configuration.RegisterComponents(c =>
            {
                c.ConfigureComponent<Repository>(DependencyLifecycle.InstancePerUnitOfWork);

                });
        }

        public void Run(Configure config)
        {
            config.NES();
        }
    }

里面的Web.config我配置如下:

<configSections>
       <section name="TransportConfig" type="NServiceBus.Config.TransportConfig, NServiceBus.Core" />
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
    <section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
   </configSections>

 <TransportConfig MaxRetries="5" MaximumConcurrencyLevel="1" MaximumMessageThroughputPerSecond="0" />
  <UnicastBusConfig>
    <MessageEndpointMappings>
      <add Messages="Registration" Endpoint="Registration" />
    </MessageEndpointMappings>
  </UnicastBusConfig>
  <MessageForwardingInCaseOfFaultConfig ErrorQueue="RegistrationEndPoint.Errors" />

里面Global.asax.cs我注册了ISendOnlyBus如下:

public static ISendOnlyBus Bus { get; private set; }
        private void RegisterBus()
        {
            var busConfiguration = new BusConfiguration();
            busConfiguration.UseSerialization<JsonSerializer>();
            busConfiguration.UseTransport<MsmqTransport>();
            busConfiguration.Transactions().Disable();
            busConfiguration.PurgeOnStartup(false);

            LogManager.Use<NServiceBus.Log4Net.Log4NetFactory>();

            Bus = NServiceBus.Bus.CreateSendOnly(busConfiguration);
        }

当我单击按钮将命令发送到命令处理程序时,它不起作用。

我正在使用 NES.CQRS 框架。

问题已解决。我有一些关于依赖注入的问题,当我遇到问题时我忽略了它。现在我解决了 ioc 问题,它现在工作正常。