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 namespace DotNetCore.CAP.Internal
{ {
internal class ConsumerExecutedResult
public class ConsumerExecutedResult
{ {
public ConsumerExecutedResult(object result, string msgId, string callbackName) 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;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -15,7 +14,7 @@ using Newtonsoft.Json.Linq;


namespace DotNetCore.CAP.Internal namespace DotNetCore.CAP.Internal
{ {
internal class SubscribeInvoker : ISubscribeInvoker
public class SubscribeInvoker : ISubscribeInvoker
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IServiceProvider _serviceProvider; private readonly IServiceProvider _serviceProvider;
@@ -41,20 +40,8 @@ namespace DotNetCore.CAP.Internal
using (var scope = _serviceProvider.CreateScope()) using (var scope = _serviceProvider.CreateScope())
{ {
var provider = scope.ServiceProvider; 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 message = context.DeliverMessage;
var parameterDescriptors = context.ConsumerDescriptor.Parameters; 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) private async Task<object> ExecuteWithParameterAsync(ObjectMethodExecutor executor, object @class, object[] parameter)
{ {
if (executor.IsMethodAsync) if (executor.IsMethodAsync)


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

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


Loading…
Cancel
Save