dependency-injection - asp.net 5依赖注入(inject)拦截调用方法

标签 dependency-injection asp.net-core

我正在使用asp.net 5的新DIP(依赖注入(inject))https://github.com/aspnet/DependencyInjection 。 到目前为止我做得还不错。

但现在是时候做更复杂的事情了。正如我过去对温莎城堡或 Unity 所做的那样。 我需要为一个类创建一个代理,以拦截调用并记录它。

AOP(面向方面​​的程序)

在温莎城堡中,它被称为:DinamicProxy 在 asp.net 5 中我怎样才能做出同样的事情?

例如:

public interface ITracingInterceptorHelper
{
    void BeforeCall(string typeName, string methodName, Dictionary<string, object> parameters);
    void ErrorOnCall(string typeName, string methodName, Exception e);
    void AfterCall(string typeName, string methodName, object returnValue);
}


public class TracingInterceptor : BaseInterceptor, IInterceptor
    {
        private readonly ITracingInterceptorHelper _helper;

        public TracingInterceptor(ITracingInterceptorHelper tracingInterceptorHelper)
        {
            _helper = tracingInterceptorHelper;
        }


        public void Intercept(IInvocation invocation)
        {
        //...
        }
    }

谢谢。问候

最佳答案

In asp.net 5 how i can make the same?

你不能。这对于 ASP.NET 5 的内置容器来说是不可能的。内置容器不适合 any considerably sized application that follows the SOLID principles and apply AOP .

如果您使用的容器工作正常,您尤其不应该“降级”到内置容器。

关于dependency-injection - asp.net 5依赖注入(inject)拦截调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33813289/

相关文章:

c# - ASP.Net Core 2.1 ASPNETCORE_ENVIRONMENT 值未反射(reflect)

c# - Nopcommerce View 未更新

c# - AspNetCore如何将css和js注入(inject)到它的开发者异常页面中?

c# - 是否可以从第 3 方应用程序执行对 Azure App Insight 的查询

java - Dagger 2 : inject an interface in a constructor

.net - IoC 容器,在编译时检查错误

java - 基于条件的依赖注入(inject)

asp.net-core - 从 ASP.NET Core 2.1 应用程序中删除 "Server" header

.net - Unity Application Block 项目进展如何?

c# - Autofac - InstancePerHttpRequest 与 InstancePerLifetimeScope