From 725a3a45f233b55cf7fb470aed4f354039f324e8 Mon Sep 17 00:00:00 2001 From: yangxiaodong Date: Mon, 11 Sep 2017 15:41:36 +0800 Subject: [PATCH] refactor and remove reference of IServiceProvider --- src/DotNetCore.CAP/Abstractions/IConsumerServiceSelector.cs | 5 ++--- src/DotNetCore.CAP/IConsumerHandler.Default.cs | 2 +- .../Internal/IConsumerServiceSelector.Default.cs | 6 +++--- src/DotNetCore.CAP/Internal/MethodMatcherCache.cs | 5 ++--- test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs | 4 ++-- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/DotNetCore.CAP/Abstractions/IConsumerServiceSelector.cs b/src/DotNetCore.CAP/Abstractions/IConsumerServiceSelector.cs index b9e1e03..e7985d7 100644 --- a/src/DotNetCore.CAP/Abstractions/IConsumerServiceSelector.cs +++ b/src/DotNetCore.CAP/Abstractions/IConsumerServiceSelector.cs @@ -11,10 +11,9 @@ namespace DotNetCore.CAP.Abstractions /// /// Selects a set of candidates for the current message associated with /// . - /// - /// . + /// /// A set of candidates or null. - IReadOnlyList SelectCandidates(IServiceProvider provider); + IReadOnlyList SelectCandidates(); /// /// Selects the best candidate from for the diff --git a/src/DotNetCore.CAP/IConsumerHandler.Default.cs b/src/DotNetCore.CAP/IConsumerHandler.Default.cs index 2990e8b..4e69e12 100644 --- a/src/DotNetCore.CAP/IConsumerHandler.Default.cs +++ b/src/DotNetCore.CAP/IConsumerHandler.Default.cs @@ -47,7 +47,7 @@ namespace DotNetCore.CAP public void Start() { - var groupingMatchs = _selector.GetCandidatesMethodsOfGroupNameGrouped(_serviceProvider); + var groupingMatchs = _selector.GetCandidatesMethodsOfGroupNameGrouped(); foreach (var matchGroup in groupingMatchs) { diff --git a/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs b/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs index 6bf8795..2f42690 100644 --- a/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs +++ b/src/DotNetCore.CAP/Internal/IConsumerServiceSelector.Default.cs @@ -33,13 +33,13 @@ namespace DotNetCore.CAP.Internal return executeDescriptor.FirstOrDefault(x => x.Attribute.Name == key); } - public IReadOnlyList SelectCandidates(IServiceProvider provider) + public IReadOnlyList SelectCandidates() { var executorDescriptorList = new List(); - executorDescriptorList.AddRange(FindConsumersFromInterfaceTypes(provider)); + executorDescriptorList.AddRange(FindConsumersFromInterfaceTypes(_serviceProvider)); - executorDescriptorList.AddRange(FindConsumersFromControllerTypes(provider)); + executorDescriptorList.AddRange(FindConsumersFromControllerTypes(_serviceProvider)); return executorDescriptorList; } diff --git a/src/DotNetCore.CAP/Internal/MethodMatcherCache.cs b/src/DotNetCore.CAP/Internal/MethodMatcherCache.cs index 332158b..db59fcc 100644 --- a/src/DotNetCore.CAP/Internal/MethodMatcherCache.cs +++ b/src/DotNetCore.CAP/Internal/MethodMatcherCache.cs @@ -22,12 +22,11 @@ namespace DotNetCore.CAP.Internal /// Get a dictionary of candidates.In the dictionary, /// the Key is the CAPSubscribeAttribute Group, the Value for the current Group of candidates /// - /// - public ConcurrentDictionary> GetCandidatesMethodsOfGroupNameGrouped(IServiceProvider provider) + public ConcurrentDictionary> GetCandidatesMethodsOfGroupNameGrouped() { if (Entries.Count != 0) return Entries; - var executorCollection = _selector.SelectCandidates(provider); + var executorCollection = _selector.SelectCandidates(); var groupedCandidates = executorCollection.GroupBy(x => x.Attribute.Group); diff --git a/test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs b/test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs index 5ed56e1..7704e88 100644 --- a/test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs +++ b/test/DotNetCore.CAP.Test/ConsumerServiceSelectorTest.cs @@ -25,7 +25,7 @@ namespace DotNetCore.CAP.Test public void CanFindAllConsumerService() { var selector = _provider.GetRequiredService(); - var candidates = selector.SelectCandidates(_provider); + var candidates = selector.SelectCandidates(); Assert.Equal(2, candidates.Count); } @@ -34,7 +34,7 @@ namespace DotNetCore.CAP.Test public void CanFindSpecifiedTopic() { var selector = _provider.GetRequiredService(); - var candidates = selector.SelectCandidates(_provider); + var candidates = selector.SelectCandidates(); var bestCandidates = selector.SelectBestCandidate("Candidates.Foo", candidates); Assert.NotNull(bestCandidates);