加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 09:55:36 所属栏目:asp.Net 来源:网络整理
导读:我正在使用asp.net 5 https://github.com/aspnet/DependencyInjection的新DIP(依赖注入). 到目前为止,我做得很好. 但现在是时候做更复杂的事了.正如我过去在Windsor Castle或Unity所做的那样. 我需要为一个类创建一个代理,拦截调用并记录它. AOP(面向方面??
我正在使用asp.net 5 https://github.com/aspnet/DependencyInjection的新DIP(依赖注入).
到目前为止,我做得很好.

但现在是时候做更复杂的事了.正如我过去在Windsor Castle或Unity所做的那样.
我需要为一个类创建一个代理,拦截调用并记录它.

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

在Windsord城堡,它被称为:DinamicProxy
在asp.net 5我怎么能做同样的?

例如:

public interface ITracingInterceptorHelper
{
    void BeforeCall(string typeName,string methodName,Dictionary<string,object> parameters);
    void ErrorOnCall(string typeName,Exception e);
    void AfterCall(string typeName,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.

如果您使用的容器正常工作,您应该特别不要“降级”到内置容器.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读