From 8c5da12d83346b9619864d3ded99abb8c285d8a6 Mon Sep 17 00:00:00 2001 From: yangxiaodong Date: Thu, 17 Aug 2017 15:57:19 +0800 Subject: [PATCH] fixed consumer method injection context bug. (#34) --- .../Internal/ConsumerInvokerFactory.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/DotNetCore.CAP/Internal/ConsumerInvokerFactory.cs b/src/DotNetCore.CAP/Internal/ConsumerInvokerFactory.cs index 0921e1b..ea200d7 100644 --- a/src/DotNetCore.CAP/Internal/ConsumerInvokerFactory.cs +++ b/src/DotNetCore.CAP/Internal/ConsumerInvokerFactory.cs @@ -1,5 +1,6 @@ using System; using DotNetCore.CAP.Abstractions; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace DotNetCore.CAP.Internal @@ -22,12 +23,15 @@ namespace DotNetCore.CAP.Internal public IConsumerInvoker CreateInvoker(ConsumerContext consumerContext) { - var context = new ConsumerInvokerContext(consumerContext) + using(var scope = _serviceProvider.CreateScope()) { - Result = new DefaultConsumerInvoker(_logger, _serviceProvider, _modelBinderFactory, consumerContext) - }; + var context = new ConsumerInvokerContext(consumerContext) + { + Result = new DefaultConsumerInvoker(_logger, scope.ServiceProvider, _modelBinderFactory, consumerContext) + }; - return context.Result; + return context.Result; + } } } } \ No newline at end of file