Browse Source

fixed issue #45

master
Savorboard 7 years ago
parent
commit
53f72d8ec4
2 changed files with 25 additions and 24 deletions
  1. +5
    -8
      src/DotNetCore.CAP/Internal/ConsumerInvokerFactory.cs
  2. +20
    -16
      src/DotNetCore.CAP/Internal/IConsumerInvoker.Default.cs

+ 5
- 8
src/DotNetCore.CAP/Internal/ConsumerInvokerFactory.cs View File

@@ -1,6 +1,5 @@
using System;
using DotNetCore.CAP.Abstractions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace DotNetCore.CAP.Internal
@@ -23,15 +22,13 @@ namespace DotNetCore.CAP.Internal

public IConsumerInvoker CreateInvoker(ConsumerContext consumerContext)
{
using (var scope = _serviceProvider.CreateScope())
var context = new ConsumerInvokerContext(consumerContext)
{
var context = new ConsumerInvokerContext(consumerContext)
{
Result = new DefaultConsumerInvoker(_logger, scope.ServiceProvider, _modelBinderFactory, consumerContext)
};
Result = new DefaultConsumerInvoker(_logger, _serviceProvider,
_modelBinderFactory, consumerContext)
};

return context.Result;
}
return context.Result;
}
}
}

+ 20
- 16
src/DotNetCore.CAP/Internal/IConsumerInvoker.Default.cs View File

@@ -35,25 +35,29 @@ namespace DotNetCore.CAP.Internal
{
_logger.LogDebug("Executing consumer Topic: {0}", _consumerContext.ConsumerDescriptor.MethodInfo.Name);

var obj = ActivatorUtilities.GetServiceOrCreateInstance(_serviceProvider,
_consumerContext.ConsumerDescriptor.ImplTypeInfo.AsType());
using (var scope = _serviceProvider.CreateScope())
{
var provider = scope.ServiceProvider;
var serviceType = _consumerContext.ConsumerDescriptor.ImplTypeInfo.AsType();
var obj = ActivatorUtilities.GetServiceOrCreateInstance(provider, serviceType);

var jsonConent = _consumerContext.DeliverMessage.Content;
var message = Helper.FromJson<Message>(jsonConent);
var jsonConent = _consumerContext.DeliverMessage.Content;
var message = Helper.FromJson<Message>(jsonConent);

object result = null;
if (_executor.MethodParameters.Length > 0)
{
result = await ExecuteWithParameterAsync(obj, message.Content.ToString());
}
else
{
result = await ExecuteAsync(obj);
}
object result = null;
if (_executor.MethodParameters.Length > 0)
{
result = await ExecuteWithParameterAsync(obj, message.Content.ToString());
}
else
{
result = await ExecuteAsync(obj);
}

if (!string.IsNullOrEmpty(message.CallbackName))
{
await SentCallbackMessage(message.Id, message.CallbackName, result);
if (!string.IsNullOrEmpty(message.CallbackName))
{
await SentCallbackMessage(message.Id, message.CallbackName, result);
}
}
}



Loading…
Cancel
Save