NES- Command不会发送给CommandHandler

时间:2016-02-26 14:11:15

标签: nservicebus cqrs neventstore

我的命令类如下:

try-with-resources

My Command Handler类如下:

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; }          
    }

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

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);

在Web.config中,我配置如下:

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();
        }
    }

在Global.asax.cs中,我按如下方式注册了ISendOnlyBus:

<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" />

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

我正在使用NES.CQRS框架。

1 个答案:

答案 0 :(得分:-3)

解决了这个问题。我有一些问题被认为是依赖注入,当我受苦时我忽略了它。现在我修复了ioc问题,它现在正常工作。