本文整理汇总了C#中IEventPublisher.Publish方法的典型用法代码示例。如果您正苦于以下问题:C# IEventPublisher.Publish方法的具体用法?C# IEventPublisher.Publish怎么用?C# IEventPublisher.Publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEventPublisher
的用法示例。
在下文中一共展示了IEventPublisher.Publish方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CommandVersioningHandlerModule
public CommandVersioningHandlerModule(IEventPublisher publisher)
{
For<CommandMessage<CreateTShirtV2>>()
.Handle((_, __) => { throw new NotSupportedException(); });
For<CommandMessage<CreateTShirtV3>>()
.Handle((commandMessage, ct) =>
{
var command = new CreateTShirtV4
{
Name = commandMessage.Command.Name,
Sizes = commandMessage.Command.Sizes,
Colors = commandMessage.Command.Colors,
BlankType = "Round"
};
var upconvertedCommand = new CommandMessage<CreateTShirtV4>(
commandMessage.CommandId,
commandMessage.RequestUser,
command);
return this.DispatchSingle(upconvertedCommand, ct);
});
For<CommandMessage<CreateTShirtV4>>()
.Handle((commandMessage, ct) =>
{
publisher.Publish(new TShirtCreatedV4
{
BlankType = commandMessage.Command.BlankType,
Name = commandMessage.Command.Name,
Colors = commandMessage.Command.Colors,
Sizes = commandMessage.Command.Sizes
});
return Task.FromResult(true);
});
}
示例2: ProcessOrder
public void ProcessOrder(Order order, IEventPublisher eventPublisher)
{
if (Equals(order.ServiceType, ServiceType.Delivery))
{
eventPublisher.Publish(new OrderNeedsDelivery(this));
}
}
示例3: WhenIIssueACreateElectionCommand
public void WhenIIssueACreateElectionCommand()
{
//setup the "bus" components
m_commandDispatcher = new CommandDispatcher();
m_eventPublisher = new EventDispatcher();
//register the command handler
var repository = MockRepository.GenerateStub<IRepository<Election>>();
m_commandDispatcher.Register(new MakeAnElectionCommandHandler(repository, null));
//register the event handler
m_eventPublisher.RegisterHandler<ElectionMadeEvent>(@event => m_electionCreatedEvent = @event);
//wire-up the domain event to the event publisher
DomainEvents.Register<ElectionMadeEvent>(@event => m_eventPublisher.Publish(@event));
//create and send the command
var command = new MakeAnElection
{
AdministratorCode = "AdmCode",
CompanyCode = "CoCode",
ParticipantId = "12345",
ElectionAmount = 1000,
ElectionReason = "election reason",
};
m_commandDispatcher.Dispatch<MakeAnElection>(command);
Assert.Pass();
}