My Command Class is as follows:
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; }
}
My Command Handler class is as follows:
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);
}
}
I send the command to bus from my controller's action method as follows:
this.commandBus.Send(command);
The End point configuration is as follows:
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();
}
}
Inside the Web.config I configured as follows:
<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" />
Inside Global.asax.cs I registered ISendOnlyBus as follows:
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);
}
When I click on button to send the command to command handler it doesn't work.
I am using NES.CQRS framework.
Solved the issue. I had some problem regarded to dependency injection and I ignored it when I was suffered. Now I fixed ioc problem and it's now working fine.