Browse Source

Change ISubscribeInvoker interface access modifier. #537

master
Savorboard 4 years ago
parent
commit
879d147175
3 changed files with 23 additions and 17 deletions
  1. +1
    -1
      src/DotNetCore.CAP/Internal/ConsumerExecutedResult.cs
  2. +21
    -15
      src/DotNetCore.CAP/Internal/ISubscribeInvoker.Default.cs
  3. +1
    -1
      src/DotNetCore.CAP/Internal/ISubscribeInvoker.cs

+ 1
- 1
src/DotNetCore.CAP/Internal/ConsumerExecutedResult.cs View File

@@ -3,7 +3,7 @@

namespace DotNetCore.CAP.Internal
{
internal class ConsumerExecutedResult
public class ConsumerExecutedResult
{
public ConsumerExecutedResult(object result, string msgId, string callbackName)
{


+ 21
- 15
src/DotNetCore.CAP/Internal/ISubscribeInvoker.Default.cs View File

@@ -3,7 +3,6 @@

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -15,7 +14,7 @@ using Newtonsoft.Json.Linq;

namespace DotNetCore.CAP.Internal
{
internal class SubscribeInvoker : ISubscribeInvoker
public class SubscribeInvoker : ISubscribeInvoker
{
private readonly ILogger _logger;
private readonly IServiceProvider _serviceProvider;
@@ -41,20 +40,8 @@ namespace DotNetCore.CAP.Internal
using (var scope = _serviceProvider.CreateScope())
{
var provider = scope.ServiceProvider;
var srvType = context.ConsumerDescriptor.ServiceTypeInfo?.AsType();
var implType = context.ConsumerDescriptor.ImplTypeInfo.AsType();

object obj = null;

if (srvType != null)
{
obj = provider.GetServices(srvType).FirstOrDefault(o => o.GetType() == implType);
}

if (obj == null)
{
obj = ActivatorUtilities.GetServiceOrCreateInstance(provider, implType);
}
var obj = GetInstance(provider, context);

var message = context.DeliverMessage;
var parameterDescriptors = context.ConsumerDescriptor.Parameters;
@@ -83,6 +70,25 @@ namespace DotNetCore.CAP.Internal
}
}

protected virtual object GetInstance(IServiceProvider provider, ConsumerContext context)
{
var srvType = context.ConsumerDescriptor.ServiceTypeInfo?.AsType();
var implType = context.ConsumerDescriptor.ImplTypeInfo.AsType();

object obj = null;
if (srvType != null)
{
obj = provider.GetServices(srvType).FirstOrDefault(o => o.GetType() == implType);
}

if (obj == null)
{
obj = ActivatorUtilities.GetServiceOrCreateInstance(provider, implType);
}

return obj;
}

private async Task<object> ExecuteWithParameterAsync(ObjectMethodExecutor executor, object @class, object[] parameter)
{
if (executor.IsMethodAsync)


+ 1
- 1
src/DotNetCore.CAP/Internal/ISubscribeInvoker.cs View File

@@ -9,7 +9,7 @@ namespace DotNetCore.CAP.Internal
/// <summary>
/// Perform user definition method of consumers.
/// </summary>
internal interface ISubscribeInvoker
public interface ISubscribeInvoker
{
/// <summary>
/// Invoke subscribe method with the consumer context.


Loading…
Cancel
Save