小编Adr*_*eck的帖子

是否可以使用面向方面的方法通过 Autofac 和 DynamicProxy 登录 Azure 函数

是否可以使用面向方面的方法通过 Autofac 和 DynamicProxy 登录 Azure 函数,如下所示:

https://nearsoft.com/blog/aspect-oriented-programming-aop-in-net-core-and-c-using-autofac-and-dynamicproxy/

我研究了以下链接

  1. http://codingsoul.de/2018/01/19/azure-function-dependency-injection-with-autofac/
  2. https://blog.wille-zone.de/post/azure-functions-proper-dependency-injection/
  3. http://autofaccn.readthedocs.io/en/latest/advanced/interceptors.html

然后尝试使用下面的代码扩展 Holger Leichsenring 的帖子(#1)。但是, Intercept() 函数从未被触发。有任何想法吗?

其他 Nuget 参考(您还需要将 Autofac 降级到 4.0.1)

using Autofac.Extras.DynamicProxy;
using Castle.DynamicProxy;
Run Code Online (Sandbox Code Playgroud)

测试它

添加拦截器和一个带参数的函数...

[Intercept(typeof(ICallLogger))]
public class TestIt : ITestIt
{
    public string Name { get; set; }

    public string CallMe()
    {
        return "Dependency Injection Test method had been called...";
    }

    public string CallMeWithParameter(string parameter)
    {
        return "Dependency Injection Test method had been called with [" + parameter + "]";
    }
}
Run Code Online (Sandbox Code Playgroud)

服务模块

public …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection azure autofac azure-functions

5
推荐指数
1
解决办法
495
查看次数