diff --git a/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs b/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs index 6bf8795..24c04db 100644 --- a/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs +++ b/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs @@ -48,19 +48,23 @@ namespace DotNetCore.CAP.Internal IServiceProvider provider) { var executorDescriptorList = new List(); - - var consumerServices = provider.GetServices(); - foreach (var service in consumerServices) + + using (var scoped = provider.CreateScope()) { - var typeInfo = service.GetType().GetTypeInfo(); - if (!typeof(ICapSubscribe).GetTypeInfo().IsAssignableFrom(typeInfo)) + var scopedProvider = scoped.ServiceProvider; + var consumerServices = scopedProvider.GetServices(); + foreach (var service in consumerServices) { - continue; - } + var typeInfo = service.GetType().GetTypeInfo(); + if (!typeof(ICapSubscribe).GetTypeInfo().IsAssignableFrom(typeInfo)) + { + continue; + } - executorDescriptorList.AddRange(GetTopicAttributesDescription(typeInfo)); + executorDescriptorList.AddRange(GetTopicAttributesDescription(typeInfo)); + } + return executorDescriptorList; } - return executorDescriptorList; } private static IEnumerable FindConsumersFromControllerTypes( @@ -76,7 +80,7 @@ namespace DotNetCore.CAP.Internal { executorDescriptorList.AddRange(GetTopicAttributesDescription(typeInfo)); } - } + } return executorDescriptorList; }