diff --git a/src/DaemonTests/Subscriptions/subscriptions_end_to_end.cs b/src/DaemonTests/Subscriptions/subscriptions_end_to_end.cs index 7cc3808d99..338a5dae2e 100644 --- a/src/DaemonTests/Subscriptions/subscriptions_end_to_end.cs +++ b/src/DaemonTests/Subscriptions/subscriptions_end_to_end.cs @@ -498,6 +498,37 @@ public void Dispose() } } +public class FilteredSubscription2: SubscriptionBase, IAsyncDisposable +{ + public FilteredSubscription2() + { + IncludeType(); + IncludeType(); + StreamType = typeof(SimpleAggregate); + IncludeArchivedEvents = true; + } + + public override Task ProcessEventsAsync(EventRange page, ISubscriptionController controller, IDocumentOperations operations, + CancellationToken cancellationToken) + { + return Task.FromResult(Substitute.For()); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + // TODO release managed resources here + } + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } +} + public class SimpleSubscription: ISubscription { public static int InstanceCounter = 0; diff --git a/src/Marten/Subscriptions/SubscriptionWrapper.cs b/src/Marten/Subscriptions/SubscriptionWrapper.cs index ad420fbe07..0c75417474 100644 --- a/src/Marten/Subscriptions/SubscriptionWrapper.cs +++ b/src/Marten/Subscriptions/SubscriptionWrapper.cs @@ -35,18 +35,14 @@ public ScopedSubscriptionServiceWrapper(IServiceProvider provider) _provider = provider; SubscriptionName = typeof(T).Name; - if (typeof(T).CanBeCastTo()) - { - using var scope = _provider.CreateScope(); - var sp = scope.ServiceProvider; - - var subscription = sp.GetRequiredService().As(); - IncludedEventTypes.AddRange(subscription.IncludedEventTypes); - StreamType = subscription.StreamType; - IncludeArchivedEvents = subscription.IncludeArchivedEvents; - } - + var scope = _provider.CreateAsyncScope(); + var sp = scope.ServiceProvider; + var subscription = sp.GetRequiredService().As(); + IncludedEventTypes.AddRange(subscription.IncludedEventTypes); + StreamType = subscription.StreamType; + IncludeArchivedEvents = subscription.IncludeArchivedEvents; + scope.SafeDispose(); } public override async Task ProcessEventsAsync(EventRange page, ISubscriptionController controller,