我正在使用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/