Giter Site home page Giter Site logo

dora's People

Contributors

jiangjinnan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dora's Issues

Cannot get TypeToken for a ByRef type

When we Execute a method with return type void and it contains a byRef paramter it shows the error bellow:

this method is interceptable, but throws an exception because of void and out combination.

for example public void MyMethod(string a, out int b)

It doesn't thow when we call it but it throw when we inject the interface or class

System.Reflection.Emit.ModuleBuilder.GetTypeTokenWorkerNoLock(Type type, bool getGenericDefinition) System.Reflection.Emit.ModuleBuilder.GetTypeTokenInternal(Type type, bool getGenericDefinition) System.Reflection.Emit.ILGenerator.Emit(OpCode opcode, Type cls) Dora.DynamicProxy.ILGeneratorExtensions.EmitUnboxOrCast(ILGenerator il, Type targetType) Dora.DynamicProxy.DynamicProxyClassGenerator+<>c__DisplayClass24_0.<DefineInterceptableMethod>b__1() Dora.DynamicProxy.DynamicProxyClassGenerator.DefineInterceptableMethod(MethodInfo methodInfo, MethodAttributes attributes) Dora.DynamicProxy.DynamicProxyClassGenerator.GenerateForInterface() Dora.DynamicProxy.DynamicProxyClassGenerator.GenerateProxyType() Dora.DynamicProxy.DynamicProxyFactoryCache.GetInstanceFactory(Type type, InterceptorDecoration interceptors) Dora.DynamicProxy.InterfaceDynamicProxyGenerator.Wrap(Type type, object target, InterceptorDecoration interceptors) Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, bool isDefaultParameterRequired) lambda_method(Closure , IServiceProvider , object[] ) Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider+<>c__DisplayClass4_0.<CreateActivator>b__0(ControllerContext controllerContext)

方法签名涉及 @event ,不知名原因识别为 c# Event ,导致生成报错

Dora.Interception.InterceptionException:“It fails to generate proxy class.
(267,99): error CS1001: 应输入标识符
(267,99): error CS1026: 应输入 )
(267,99): error CS1002: 应输入 ;
(267,104): error CS1031: 应输入类型
(267,104): error CS1514: 应为 {
(267,104): error CS1055: 应为 add 访问器或 remove 访问器
(267,106): error CS1055: 应为 add 访问器或 remove 访问器
(267,117): error CS1055: 应为 add 访问器或 remove 访问器
(267,123): error CS1055: 应为 add 访问器或 remove 访问器
(267,125): error CS1055: 应为 add 访问器或 remove 访问器
(267,142): error CS1055: 应为 add 访问器或 remove 访问器
(267,160): error CS1055: 应为 add 访问器或 remove 访问器
(267,168): error CS1513: 应输入 }
(267,175): error CS8124: 元组必须包含至少两个元素。
(268,13): error CS1519: 类、记录、结构或接口成员声明中的标记“{”无效
(269,24): error CS1519: 类、记录、结构或接口成员声明中的标记“=”无效
(269,24): error CS1519: 类、记录、结构或接口成员声明中的标记“=”无效
(269,31): error CS1031: 应输入类型
(269,31): error CS1514: 应为 {
(269,31): error CS1055: 应为 add 访问器或 remove 访问器
(270,17): error CS1055: 应为 add 访问器或 remove 访问器
(270,28): error CS1055: 应为 add 访问器或 remove 访问器
(270,30): error CS1055: 应为 add 访问器或 remove 访问器
(271,17): error CS1055: 应为 add 访问器或 remove 访问器
(271,36): error CS1055: 应为 add 访问器或 remove 访问器
(271,38): error CS1055: 应为 add 访问器或 remove 访问器
(320,124): error CS1001: 应输入标识符
(320,124): error CS1026: 应输入 )
(320,124): error CS1002: 应输入 ;
(320,129): error CS1031: 应输入类型
(320,129): error CS1514: 应为 {
(320,129): error CS1055: 应为 add 访问器或 remove 访问器
(320,130): error CS1055: 应为 add 访问器或 remove 访问器
(324,65): error CS1525: 表达式项“event”无效
(324,65): error CS1026: 应输入 )
(324,65): error CS1002: 应输入 ;
(324,65): error CS1513: 应输入 }
(324,65): error CS1513: 应输入 }
(324,70): error CS1031: 应输入类型
(324,70): error CS1514: 应为 {
(324,70): error CS1055: 应为 add 访问器或 remove 访问器
(324,72): error CS1055: 应为 add 访问器或 remove 访问器
(324,78): error CS1055: 应为 add 访问器或 remove 访问器
(324,80): error CS1055: 应为 add 访问器或 remove 访问器
(324,85): error CS1055: 应为 add 访问器或 remove 访问器
(324,86): error CS1055: 应为 add 访问器或 remove 访问器
(324,101): error CS1055: 应为 add 访问器或 remove 访问器
(324,102): error CS1055: 应为 add 访问器或 remove 访问器
(325,13): error CS1055: 应为 add 访问器或 remove 访问器
(325,17): error CS1055: 应为 add 访问器或 remove 访问器
(325,27): error CS1055: 应为 add 访问器或 remove 访问器
(325,29): error CS1055: 应为 add 访问器或 remove 访问器
(325,60): error CS1055: 应为 add 访问器或 remove 访问器
(325,61): error CS1055: 应为 add 访问器或 remove 访问器
(325,66): error CS1055: 应为 add 访问器或 remove 访问器
(325,67): error CS1055: 应为 add 访问器或 remove 访问器
(325,73): error CS1513: 应输入 }
(325,81): error CS8124: 元组必须包含至少两个元素。
(325,82): error CS1519: 类、记录、结构或接口成员声明中的标记“;”无效
(326,17): error CS1031: 应输入类型
(326,17): error CS8124: 元组必须包含至少两个元素。
(326,17): error CS1026: 应输入 )
(326,17): error CS1519: 类、记录、结构或接口成员声明中的标记“!”无效
(326,39): error CS1519: 类、记录、结构或接口成员声明中的标记“)”无效
(326,39): error CS1519: 类、记录、结构或接口成员声明中的标记“)”无效
(327,13): error CS1519: 类、记录、结构或接口成员声明中的标记“return”无效
(327,47): error CS1519: 类、记录、结构或接口成员声明中的标记“;”无效
(327,47): error CS1519: 类、记录、结构或接口成员声明中的标记“;”无效
(352,100): error CS1001: 应输入标识符
(352,100): error CS1026: 应输入 )
(352,100): error CS1002: 应输入 ;
(352,105): error CS1031: 应输入类型
(352,105): error CS1514: 应为 {
(352,105): error CS1055: 应为 add 访问器或 remove 访问器
(352,107): error CS1055: 应为 add 访问器或 remove 访问器
(352,118): error CS1055: 应为 add 访问器或 remove 访问器
(352,124): error CS1055: 应为 add 访问器或 remove 访问器
(352,126): error CS1055: 应为 add 访问器或 remove 访问器
(352,143): error CS1055: 应为 add 访问器或 remove 访问器
(352,161): error CS1055: 应为 add 访问器或 remove 访问器
(352,169): error CS1513: 应输入 }
(352,176): error CS8124: 元组必须包含至少两个元素。
(353,13): error CS1519: 类、记录、结构或接口成员声明中的标记“{”无效
(354,24): error CS1519: 类、记录、结构或接口成员声明中的标记“=”无效
(354,24): error CS1519: 类、记录、结构或接口成员声明中的标记“=”无效
(354,31): error CS1031: 应输入类型
(354,31): error CS1514: 应为 {
(354,31): error CS1055: 应为 add 访问器或 remove 访问器
(355,17): error CS1055: 应为 add 访问器或 remove 访问器
(355,28): error CS1055: 应为 add 访问器或 remove 访问器
(355,30): error CS1055: 应为 add 访问器或 remove 访问器
(356,17): error CS1055: 应为 add 访问器或 remove 访问器
(356,36): error CS1055: 应为 add 访问器或 remove 访问器
(356,38): error CS1055: 应为 add 访问器或 remove 访问器
(405,124): error CS1001: 应输入标识符
(405,124): error CS1026: 应输入 )
(405,124): error CS1002: 应输入 ;
(405,129): error CS1031: 应输入类型
(405,129): error CS1514: 应为 {
(405,129): error CS1055: 应为 add 访问器或 remove 访问器
(405,130): error CS1055: 应为 add 访问器或 remove 访问器
(409,66): error CS1525: 表达式项“event”无效
(409,66): error CS1026: 应输入 )
(409,66): error CS1002: 应输入 ;
(409,66): error CS1513: 应输入 }
(409,66): error CS1513: 应输入 }
(409,71): error CS1031: 应输入类型
(409,71): error CS1514: 应为 {
(409,71): error CS1055: 应为 add 访问器或 remove 访问器
(409,73): error CS1055: 应为 add 访问器或 remove 访问器
(409,79): error CS1055: 应为 add 访问器或 remove 访问器
(409,81): error CS1055: 应为 add 访问器或 remove 访问器
(409,86): error CS1055: 应为 add 访问器或 remove 访问器
(409,87): error CS1055: 应为 add 访问器或 remove 访问器
(409,102): error CS1055: 应为 add 访问器或 remove 访问器
(409,103): error CS1055: 应为 add 访问器或 remove 访问器
(410,13): error CS1055: 应为 add 访问器或 remove 访问器
(410,17): error CS1055: 应为 add 访问器或 remove 访问器
(410,27): error CS1055: 应为 add 访问器或 remove 访问器
(410,29): error CS1055: 应为 add 访问器或 remove 访问器
(410,59): error CS1055: 应为 add 访问器或 remove 访问器
(410,60): error CS1055: 应为 add 访问器或 remove 访问器
(410,65): error CS1055: 应为 add 访问器或 remove 访问器
(410,66): error CS1055: 应为 add 访问器或 remove 访问器
(410,72): error CS1513: 应输入 }
(410,80): error CS8124: 元组必须包含至少两个元素。
(410,81): error CS1519: 类、记录、结构或接口成员声明中的标记“;”无效
(411,17): error CS1031: 应输入类型
(411,17): error CS8124: 元组必须包含至少两个元素。
(411,17): error CS1026: 应输入 )
(411,17): error CS1519: 类、记录、结构或接口成员声明中的标记“!”无效
(411,39): error CS1519: 类、记录、结构或接口成员声明中的标记“)”无效
(411,39): error CS1519: 类、记录、结构或接口成员声明中的标记“)”无效
(412,13): error CS1519: 类、记录、结构或接口成员声明中的标记“return”无效
(412,47): error CS1519: 类、记录、结构或接口成员声明中的标记“;”无效
(412,47): error CS1519: 类、记录、结构或接口成员声明中的标记“;”无效
(415,9): error CS8803: 顶级语句必须位于命名空间和类型声明之前。
(415,9): error CS0106: 修饰符“public”对该项无效
(422,5): error CS1022: 应输入类型、命名空间定义或文件尾
(423,1): error CS1022: 应输入类型、命名空间定义或文件尾
(330,26): error CS0116: 命名空间不能直接包含字段、方法或语句之类的成员
(338,94): error CS0246: 未能找到类型或命名空间名“IVirtualMethodProxy”(是否缺少 using 指令或程序集引用?)
(320,129): error CS0065: “SimpleHandlerProxy416694832.”: 事件属性必须同时具有 add 和 remove 访问器
(324,70): error CS0065: “SimpleHandlerProxy416694832.”: 事件属性必须同时具有 add 和 remove 访问器
(405,129): error CS0065: “SimpleHandlerProxy961835331.”: 事件属性必须同时具有 add 和 remove 访问器
(409,71): error CS0065: “SimpleHandlerProxy961835331.”: 事件属性必须同时具有 add 和 remove 访问器
(320,76): error CS1994: 只能在具有正文的方法中使用 "async" 修饰符。
(405,76): error CS1994: 只能在具有正文的方法中使用 "async" 修饰符。
(340,26): error CS0246: 未能找到类型或命名空间名“IInvocationServiceScopeFactory”(是否缺少 using 指令或程序集引用?)
(342,31): error CS0246: 未能找到类型或命名空间名“InvokeDelegate”(是否缺少 using 指令或程序集引用?)
(399,45): error CS0246: 未能找到类型或命名空间名“IInvocationServiceScopeFactory”(是否缺少 using 指令或程序集引用?)
(326,41): error CS0246: 未能找到类型或命名空间名“await”(是否缺少 using 指令或程序集引用?)
(411,41): error CS0246: 未能找到类型或命名空间名“await”(是否缺少 using 指令或程序集引用?)
(344,54): error CS0246: 未能找到类型或命名空间名“InvocationContext”(是否缺少 using 指令或程序集引用?)
(267,20): error CS0501: “SimpleHandlerProxy416694832.HandleAsyncContext166960909.HandleAsyncContext166960909(object, SimpleEvent)”必须声明主体,因为它未标记为 abstract、extern 或 partial
(267,104): error CS0065: “SimpleHandlerProxy416694832.HandleAsyncContext166960909.”: 事件属性必须同时具有 add 和 remove 访问器
(269,31): error CS0065: “SimpleHandlerProxy416694832.HandleAsyncContext166960909.”: 事件属性必须同时具有 add 和 remove 访问器
(352,20): error CS0501: “SimpleHandlerProxy961835331.HandleAsyncContext1866000012.HandleAsyncContext1866000012(object, SimpleEvent)”必须声明主体,因为它未标记为 abstract、extern 或 partial
(352,105): error CS0065: “SimpleHandlerProxy961835331.HandleAsyncContext1866000012.”: 事件属性必须同时具有 add 和 remove 访问器
(354,31): error CS0065: “SimpleHandlerProxy961835331.HandleAsyncContext1866000012.”: 事件属性必须同时具有 add 和 remove 访问器
(377,29): error CS0246: 未能找到类型或命名空间名“InvocationContext”(是否缺少 using 指令或程序集引用?)
(386,29): error CS0246: 未能找到类型或命名空间名“InvocationContext”(是否缺少 using 指令或程序集引用?)
(396,29): error CS0246: 未能找到类型或命名空间名“InvocationContext”(是否缺少 using 指令或程序集引用?)
(409,71): error CS0102: 类型“SimpleHandlerProxy961835331”已经包含“”的定义
(324,70): error CS0102: 类型“SimpleHandlerProxy416694832”已经包含“”的定义
(349,40): error CS0115: “SimpleHandlerProxy961835331.HandleAsyncContext1866000012.MethodInfo”: 没有找到适合的方法来重写
(350,46): error CS0115: “SimpleHandlerProxy961835331.HandleAsyncContext1866000012.InvocationServices”: 没有找到适合的方法来重写
(359,39): error CS0115: “SimpleHandlerProxy961835331.HandleAsyncContext1866000012.GetArgument(string)”: 没有找到适合的方法来重写
(368,39): error CS0115: “SimpleHandlerProxy961835331.HandleAsyncContext1866000012.GetArgument(int)”: 没有找到适合的方法来重写
(377,47): error CS0115: “SimpleHandlerProxy961835331.HandleAsyncContext1866000012.SetArgument(string, TArgument)”: 没有找到适合的方法来重写
(386,47): error CS0115: “SimpleHandlerProxy961835331.HandleAsyncContext1866000012.SetArgument(int, TArgument)”: 没有找到适合的方法来重写
(395,42): error CS0115: “SimpleHandlerProxy961835331.HandleAsyncContext1866000012.GetReturnValue()”: 没有找到适合的方法来重写
(396,47): error CS0115: “SimpleHandlerProxy961835331.HandleAsyncContext1866000012.SetReturnValue(TReturnValue)”: 没有找到适合的方法来重写
(354,31): error CS0102: 类型“SimpleHandlerProxy961835331.HandleAsyncContext1866000012”已经包含“”的定义
(269,31): error CS0102: 类型“SimpleHandlerProxy416694832.HandleAsyncContext166960909”已经包含“”的定义
(415,9): error CS8805: 使用顶级语句的程序必须是可执行文件。
(341,107): error CS0103: 当前上下文中不存在名称“ProxyHelper”
(332,28): error CS0246: 未能找到类型或命名空间名“HandleAsyncContext166960909”(是否缺少 using 指令或程序集引用?)
(333,36): error CS0117: “object”未包含“HandleAsync”的定义
(402,55): error CS0246: 未能找到类型或命名空间名“InvokeDelegate”(是否缺少 using 指令或程序集引用?)
(402,77): error CS0103: 当前上下文中不存在名称“MethodInvokerBuilder”
(402,160): error CS0103: 当前上下文中不存在名称“ProxyHelper”
(402,237): error CS8801: 在此上下文中,无法使用在顶级语句中声明的局部变量或本地函数“HandleAsync193556987”。
(417,28): error CS0246: 未能找到类型或命名空间名“HandleAsyncContext1866000012”(是否缺少 using 指令或程序集引用?)
(418,31): error CS1511: 关键字“base”在静态方法中不可用
(415,47): error CS0246: 未能找到类型或命名空间名“InvocationContext”(是否缺少 using 指令或程序集引用?)
(415,26): warning CS8321: 声明了本地函数“HandleAsync193556987”,但从未使用过
warning CS1701: 假定“Dora.Interception”使用的程序集引用“Microsoft.Extensions.DependencyInjection.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60”与“Microsoft.Extensions.DependencyInjection.Abstractions”的标识“Microsoft.Extensions.DependencyInjection.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60”匹配,您可能需要提供运行时策略
warning CS1701: 假定“Dora.Interception”使用的程序集引用“Microsoft.Extensions.DependencyInjection.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60”与“Microsoft.Extensions.DependencyInjection.Abstractions”的标识“Microsoft.Extensions.DependencyInjection.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60”匹配,您可能需要提供运行时策略
(317,238): error CS0103: 当前上下文中不存在名称“HandleAsync347788337”
warning CS1701: 假定“Dora.Interception”使用的程序集引用“Microsoft.Extensions.DependencyInjection.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60”与“Microsoft.Extensions.DependencyInjection.Abstractions”的标识“Microsoft.Extensions.DependencyInjection.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60”匹配,您可能需要提供运行时策略
(363,32): error CS0103: 当前上下文中不存在名称“ProxyHelper”
(372,26): error CS0103: 当前上下文中不存在名称“ProxyHelper”
(381,32): error CS0103: 当前上下文中不存在名称“ProxyHelper”
(390,26): error CS0103: 当前上下文中不存在名称“ProxyHelper”
(395,76): error CS0103: 当前上下文中不存在名称“ProxyHelper”
(396,99): error CS0103: 当前上下文中不存在名称“ProxyHelper”
(346,58): warning CS0649: 从未对字段“SimpleHandlerProxy961835331.HandleAsyncContext1866000012._event”赋值,字段将一直保持其默认值 null
(347,66): warning CS0649: 从未对字段“SimpleHandlerProxy961835331.HandleAsyncContext1866000012._returnValue”赋值,字段将一直保持其默认值 null
(326,47): warning CS0169: 从不使用字段“SimpleHandlerProxy416694832.valueTask”
(411,47): warning CS0169: 从不使用字段“SimpleHandlerProxy961835331.valueTask”” csharp

public class SimpleHandler
// : IApplicationEventListener
{
//private readonly ILogger _logger;

//public SimpleHandler(ILogger<SimpleHandler> logger)
//{
//    _logger = logger;
//}

[OperationLogging("简单消息订阅")]
public async virtual Task<bool> HandleAsync(SimpleEvent @event)
{
    //_logger.LogInformation($"{nameof(SimpleHandler)}:{@event.Name}");
    await Task.Delay(10);
    return true;
}

}

public class OperationLoggingAttribute : AspectAttribute
{
public string Name { get; protected set; }
public OperationLoggingAttribute(string name)
{
Name = name;
}

  public override async ValueTask InvokeAsync(InvocationContext invocationContext)
  {
      var logger = invocationContext.InvocationServices.GetService<ILogger<OperationLoggingAttribute>>();
      logger.LogInformation("{0} starting...", Name);
      await invocationContext.ProceedAsync();
      logger.LogInformation("{0} ended", Name);
  }

}

Need to add abstract layer

for using with 'Microsoft.Extensions.DependencyInjection.Abstractions' and so on, thanks.

可否增加抽象层,用于配合 'Microsoft.Extensions.DependencyInjection.Abstractions' 等,谢谢~

在 Autofac 的 Interceptor 和您的 Dora 之间犹豫了很久,倾向于使用 Dora 而避免引入 autofac。

急需~

Dora.DynamicProxy.InterceptDelegate

System.InvalidOperationException:“Unable to resolve service for type 'Dora.DynamicProxy.InterceptDelegate' while attempting to activate 'LKsoft.Noah.Service.GranAuthorization.DemoAuthorizaton.ArgumentConversionInterceptor'.”

DataAnnotationInterceptorProvider 注入判断问题

public override bool CanIntercept(Type targetType, MethodInfo method, out bool suppressed) 方法,对于属性是否修注入判断有误

132行应该是这样的(property?.GetCustomAttributes):
if (method.DeclaringType == targetType) { return method.GetCustomAttributes<InterceptorAttribute>(false).Any() || targetType.GetCustomAttributes<InterceptorAttribute>(false).Any() || (property?.GetCustomAttributes(false)?.Any() ?? false);
}
应该为:
if (method.DeclaringType == targetType) { return method.GetCustomAttributes<InterceptorAttribute>(false).Any() || targetType.GetCustomAttributes<InterceptorAttribute>(false).Any() || (property?.GetCustomAttributes<InterceptorAttribute>(false)?.Any() ?? false); }

mac上build失败

dotnet build
Microsoft (R) Build Engine version 15.1.1012.6693
Copyright (C) Microsoft Corporation. All rights reserved.

  Documents -> ~/Desktop/dotcore/Dora/doc/Documents/bin/Debug/netstandard1.4/Documents.dll
CSC : error CS7027: Error signing output with public key from file '../../../Key.snk' -- Assembly signing not supported. [~/Desktop/dotcore/Dora/src/Dora.Interception/Dora.Interception/Dora.Interception.csproj]
/usr/local/share/dotnet/sdk/1.0.4/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.targets(92,5): error : Cannot find project info for '~/Desktop/dotcore/Dora/src/Dora.Interception/Dora.Interception/Dora.Interception.csproj'. This can indicate a missing project reference. [~/Desktop/dotcore/Dora/src/Dora.Interception/Dora.Interception.Castle/Dora.Interception.Castle.csproj]

Build FAILED.

CSC : error CS7027: Error signing output with public key from file '../../../Key.snk' -- Assembly signing not supported. [~/Desktop/dotcore/Dora/src/Dora.Interception/Dora.Interception/Dora.Interception.csproj]
/usr/local/share/dotnet/sdk/1.0.4/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.targets(92,5): error : Cannot find project info for '~/Desktop/dotcore/Dora/src/Dora.Interception/Dora.Interception/Dora.Interception.csproj'. This can indicate a missing project reference. [~/Desktop/dotcore/Dora/src/Dora.Interception/Dora.Interception.Castle/Dora.Interception.Castle.csproj]
    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:05.11

直接使用 GetElementType 方法速度更快

public static Type GetNonByRefType(this Type type)
{
if (type.IsByRef)
{
return _mapping.TryGetValue(type, out var nonByRefType)
? nonByRefType
: _mapping[type] = Type.GetType(type.AssemblyQualifiedName.Replace("&", ""));
}
return type;
}

直接使用GetElementType方法比使用字符串Replace方法的速度更快,而且不需要使用缓存。
这是我的测试代码:

    public class GetNonByRefType_Benchmarker
    {

        private readonly Type _refType = typeof(GetNonByRefType_Benchmarker).GetMethod("Do").GetParameters()[0].ParameterType;


        [Benchmark]
        public Type Get_By_Replace()
        {
            return Type.GetType(_refType.AssemblyQualifiedName.Replace("&", ""));
        }

        [Benchmark]
        public Type Get_By_Replace_Cache()
        {
            return _refType.GetNonByRefType();
        }

        [Benchmark]
        public Type Get_By_GetElementType()
        {
            return _refType.GetElementType();
        }

        public static void Do(out string input)
        {
            input = string.Empty;
        }
    }

这是我的测试结果:

Method Mean Error StdDev
Get_By_Replace 4,083.71 ns 28.9533 ns 27.0829 ns
Get_By_Replace_Cache 30.98 ns 0.1904 ns 0.1688 ns
Get_By_GetElementType 15.54 ns 0.0805 ns 0.0753 ns

在winform或者wpf会造成死锁

 public class FoobarInterceptor
    {
        private readonly Serial _foobar;
        public string Name { get; }

        public FoobarInterceptor(string name, Serial foobar)
        {
            _foobar = foobar;
            Name = name;
        }

        public async ValueTask InvokeAsync(InvocationContext invocationContext)
        {
          // deadlock
            await _foobar.Send(new byte[6]).ConfigureAwait(false);
            await invocationContext.ProceedAsync();
        }
    }
    
   public class Serial
    {
        public virtual async Task Send(byte[] data)
        {
            await Task.Delay(100);
            Console.WriteLine("aaa");
        }
    }
    public class Invoker
    {
        [Interceptor(typeof(FoobarInterceptor), "Interceptor1")]
        public virtual void Invoke1()
        {
            Console.WriteLine("Invoker.Invoke1()");
        }
    }

 /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Invoker invoker;

        public MainWindow()
        {
            InitializeComponent();
            invoker = new ServiceCollection()
                .AddSingleton<Invoker>()
                .AddSingleton<Serial>()
                .BuildInterceptableServiceProvider()
                .GetRequiredService<Invoker>();
        }

        // 同步的
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            Console.WriteLine("dada");
            var user = Test();
            MessageBox.Show(user);
        }

        // 异步
        private string Test()
        {
            invoker.Invoke1();
            return abd;
        }
    }

还是因为同步调用异步代码导致的死锁
不知道在拦截器内部是否可以优化避免,不然针对使用者来说有点分不清楚 很难规避,而且卡死了也不会报异常,一旦遇到难以排查

关于scoped服务在InvokeAsync方法上注入失败

大佬,你好。我用你的aop框架,使用特性注入的方式,在方法InvokeAsync注入了一个scope作用域的服务,但是我得到了一个错误:Cannot resolve scoped service 'DYFrame.Entity.IUnitOfWorkManager' from root provider

下面是错误详细信息:
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred. **### (**Cannot resolve scoped service 'DYFrame.Entity.IUnitOfWorkManager' from root provider.****)
Source=System.Private.CoreLib
StackTrace:
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at IUserAppServicea158f35711b34e4cbd1f798fa2e1a7f9.Add()
at Test.EFApi.Controllers.WeatherForecastController.TestMethod() in F:\java\BasicFramework\Test\Test.EFApi\Controllers\WeatherForecastController.cs:line 47
at Microsoft.Extensions.Internal.ObjectMethodExecutor.<>c__DisplayClass33_0.b__0(Object target, Object[] parameters)
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.VoidResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<g__Logged|12_1>d.MoveNext()

此异常最初是在此调用堆栈中引发的:
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.ValidateResolution(System.Type, Microsoft.Extensions.DependencyInjection.IServiceScope, Microsoft.Extensions.DependencyInjection.IServiceScope)
Microsoft.Extensions.DependencyInjection.ServiceProvider.Microsoft.Extensions.DependencyInjection.ServiceLookup.IServiceProviderEngineCallback.OnResolve(System.Type, Microsoft.Extensions.DependencyInjection.IServiceScope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(System.Type, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope)
Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(System.Type)
Dora.Interception.InterceptorChainBuilderExtensions.Use.AnonymousMethod__1(Dora.Interception.InvocationContext)

内部异常 1:
InvalidOperationException: Cannot resolve scoped service 'DYFrame.Entity.IUnitOfWorkManager' from root provider.

IUnitOfWorkManager 这是我定义的一个scope作用域的服务

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.