1
0
mirror of synced 2024-11-23 17:33:49 +00:00
Tapeti/Examples/01-PublishSubscribe/ExamplePublisher.cs
Mark van Renswoude 7389b5bf06 [skip appveyor] #9 Documentation and examples
Added DataAnnotations to all examples.
Implemented third example for Flow. Fixed a bug where Start would not give up it's flow lock.
2019-08-16 11:47:57 +02:00

46 lines
1.3 KiB
C#

using System;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Messaging.TapetiExample;
using Tapeti;
namespace _01_PublishSubscribe
{
public class ExamplePublisher
{
private readonly IPublisher publisher;
/// <summary>
/// Shows that the IPublisher is registered in the container by Tapeti
/// </summary>
/// <param name="publisher"></param>
public ExamplePublisher(IPublisher publisher)
{
this.publisher = publisher;
}
public async Task SendTestMessage()
{
await publisher.Publish(new PublishSubscribeMessage
{
Greeting = "Hello world of messaging!"
});
// Demonstrates what happens when DataAnnotations is enabled
// and the message is invalid
try
{
await publisher.Publish(new PublishSubscribeMessage());
Console.WriteLine("This is not supposed to show. Did you disable the DataAnnotations extension?");
}
catch (ValidationException e)
{
Console.WriteLine("As expected, the DataAnnotations check failed: " + e.Message);
}
}
}
}