Procházet zdrojové kódy

add custom message wapper interface

undefined
Savorboard před 7 roky
rodič
revize
bf65b82ed0
2 změnil soubory, kde provedl 9 přidání a 4 odebrání
  1. +4
    -1
      src/DotNetCore.CAP/Internal/ConsumerInvokerFactory.cs
  2. +5
    -3
      src/DotNetCore.CAP/Internal/IConsumerInvoker.Default.cs

+ 4
- 1
src/DotNetCore.CAP/Internal/ConsumerInvokerFactory.cs Zobrazit soubor

@@ -7,15 +7,18 @@ namespace DotNetCore.CAP.Internal
public class ConsumerInvokerFactory : IConsumerInvokerFactory
{
private readonly ILogger _logger;
private readonly IMessagePacker _messagePacker;
private readonly IModelBinderFactory _modelBinderFactory;
private readonly IServiceProvider _serviceProvider;

public ConsumerInvokerFactory(
ILoggerFactory loggerFactory,
IMessagePacker messagePacker,
IModelBinderFactory modelBinderFactory,
IServiceProvider serviceProvider)
{
_logger = loggerFactory.CreateLogger<ConsumerInvokerFactory>();
_messagePacker = messagePacker;
_modelBinderFactory = modelBinderFactory;
_serviceProvider = serviceProvider;
}
@@ -24,7 +27,7 @@ namespace DotNetCore.CAP.Internal
{
var context = new ConsumerInvokerContext(consumerContext)
{
Result = new DefaultConsumerInvoker(_logger, _serviceProvider,
Result = new DefaultConsumerInvoker(_logger, _serviceProvider, _messagePacker,
_modelBinderFactory, consumerContext)
};



+ 5
- 3
src/DotNetCore.CAP/Internal/IConsumerInvoker.Default.cs Zobrazit soubor

@@ -16,14 +16,17 @@ namespace DotNetCore.CAP.Internal
private readonly ILogger _logger;
private readonly IModelBinderFactory _modelBinderFactory;
private readonly IServiceProvider _serviceProvider;
private readonly IMessagePacker _messagePacker;

public DefaultConsumerInvoker(ILogger logger,
IServiceProvider serviceProvider,
IMessagePacker messagePacker,
IModelBinderFactory modelBinderFactory,
ConsumerContext consumerContext)
{
_modelBinderFactory = modelBinderFactory;
_serviceProvider = serviceProvider;
_messagePacker = messagePacker;
_logger = logger;
_consumerContext = consumerContext;

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

var serializer = _serviceProvider.GetService<IContentSerializer>();
using (var scope = _serviceProvider.CreateScope())
{
var provider = scope.ServiceProvider;
@@ -43,8 +45,8 @@ namespace DotNetCore.CAP.Internal
var obj = ActivatorUtilities.GetServiceOrCreateInstance(provider, serviceType);

var jsonContent = _consumerContext.DeliverMessage.Content;
var message = serializer.DeSerialize<CapMessageDto>(jsonContent);
var message = _messagePacker.UnPack(jsonContent);
object result;
if (_executor.MethodParameters.Length > 0)
result = await ExecuteWithParameterAsync(obj, message.Content);


Načítá se…
Zrušit
Uložit