diff --git a/src/DaemonTests/Subscriptions/subscriptions_end_to_end.cs b/src/DaemonTests/Subscriptions/subscriptions_end_to_end.cs index daaaaa3c82..a20eee9397 100644 --- a/src/DaemonTests/Subscriptions/subscriptions_end_to_end.cs +++ b/src/DaemonTests/Subscriptions/subscriptions_end_to_end.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using EventSourcingTests.Aggregation; using JasperFx.Core; using Lamar.IoC.Instances; using Marten; @@ -15,6 +16,7 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Npgsql; +using NSubstitute; using Shouldly; using Weasel.Postgresql; using Xunit; @@ -446,6 +448,53 @@ public async Task use_from_service_provider_as_scoped_with_martenStore() await store.Advanced.Clean.DeleteAllEventDataAsync(); } + + [Fact] + public void subscription_wrapper_copies_the_filters_from_subscription_base() + { + var services = new ServiceCollection(); + services.AddScoped(); + + var provider = services.BuildServiceProvider(); + + var wrapper = new ScopedSubscriptionServiceWrapper(provider); + + wrapper.IncludeArchivedEvents.ShouldBeTrue(); + wrapper.IncludedEventTypes.Count.ShouldBe(2); + wrapper.IncludedEventTypes.ShouldContain(typeof(AEvent)); + wrapper.IncludedEventTypes.ShouldContain(typeof(BEvent)); + } +} + +public class FilteredSubscription: SubscriptionBase, IDisposable +{ + public FilteredSubscription() + { + 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 diff --git a/src/Marten/Subscriptions/SubscriptionWrapper.cs b/src/Marten/Subscriptions/SubscriptionWrapper.cs index eff08a070d..ad420fbe07 100644 --- a/src/Marten/Subscriptions/SubscriptionWrapper.cs +++ b/src/Marten/Subscriptions/SubscriptionWrapper.cs @@ -2,6 +2,7 @@ using System.Threading; using System.Threading.Tasks; using JasperFx.Core; +using JasperFx.Core.Reflection; using Marten.Events.Daemon; using Marten.Events.Daemon.Internals; using Microsoft.Extensions.DependencyInjection; @@ -33,6 +34,19 @@ 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; + } + + } public override async Task ProcessEventsAsync(EventRange page, ISubscriptionController controller,