コード例 #1
0
        public EventSubscriptionTests() : base(false)
        {
            _waitHandle = new AutoResetEvent(false);
            var subscriptionBuilder = new EventSubscriptionBuilder();

            subscriptionBuilder.As <IEventSubscriptionBuilder>()
            .On <TestCreated>()
            .HandleAsync(e =>
            {
                _eventCounter++;
                return(Task.CompletedTask);
            })
            .On <TestDone>()
            .HandleAsync(e =>
            {
                _eventCounter++;
                _waitHandle.Set();
                return(Task.CompletedTask);
            })
            .RetryOnError((e, ex) => false);

            ServiceCollection
            .AddSingleton <IEventSubscription, NEventStoreEventSubscription>()
            .AddSingleton <NEventStoreEventSubscription>()
            .AddSingleton(typeof(IEventSubscriptionBuilder), subscriptionBuilder)
            .AddSingleton(typeof(IHandlerResolver), subscriptionBuilder)
            .AddSingleton(subscriptionBuilder.CheckpointLoader);

            _eventSubscription = Services.GetRequiredService <IEventSubscription>();
            _eventSubscription.StartAsync().GetAwaiter().GetResult();
        }
コード例 #2
0
 public Task StartAsync(CancellationToken cancellationToken)
 {
     return(_subscription.StartAsync(cancellationToken));
 }