Exemple #1
0
        private static async Task RunNormalDemo()
        {
            var builder = new EventHubBuilder();

            builder.AddSubscriber(new PrintingEventHandler <int>(Console.Out));
            builder.AddSubscriber(new PrintingEventHandler <string>(Console.Out));
            builder.AddSubscriber(new PrintingEventHandler <string>(Console.Out, "Pretend I'm sending an email."));
            builder.AddSubscriber(
                new PrintingEventHandler <string>(Console.Out, "Pretend I'm sending a Discord message."));
            var hub = builder.CreateHub();

            await hub.Dispatch(42);

            await hub.Dispatch("Hello world.");

            await hub.Dispatch("Hello Kai!");

            await hub.Dispatch(84L);
        }
Exemple #2
0
        private static async Task RunThrowsDemo()
        {
            var builder = new EventHubBuilder();

            builder.ThrowsOnResultFailure(evt =>
                                          new BusinessException($"Business logic exception, event is \"{evt}\""));
            builder.AddSubscriber(new FailingEventHandler());
            var hub = builder.CreateHub();

            await hub.Dispatch("Eh?");
        }