使用StructureMap.DynamicInterception进行面向方面的编程 [英] Aspect Oriented Programming with StructureMap.DynamicInterception

查看:99
本文介绍了使用StructureMap.DynamicInterception进行面向方面的编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个在结构图上使用DynamicInterception的控制台应用程序,我遵循页面上的示例 StructureMap动态拦截. 现在,我正在尝试将代码传递给asp.net MVC网站,但出现以下错误

I implemented a console app that uses DynamicInterception on structure map, I follow the example on the page StructureMap DynamicInterception. Now I'm trying to pass the code to a asp.net MVC site but I get the following error

装饰器拦截器在对象构造期间失败.看到内部异常:

Decorator Interceptor failed during object construction. See the inner exception:

1.)具有拦截功能的ITSector.Site.Core.Controllers.HomeController的DynamicProxyInterceptor 行为:ITSector.Library.Aspect.LoggerInterceptor 2.)ITSector.Site.Core.Controllers.HomeController 3.)ITSector.Site.Core.Controllers.HomeController的实例 4.)Container.GetInstance(ITSector.Site.Core.Controllers.HomeController)

1.) DynamicProxyInterceptor of ITSector.Site.Core.Controllers.HomeController with interception behaviors: ITSector.Library.Aspect.LoggerInterceptor 2.) ITSector.Site.Core.Controllers.HomeController 3.) Instance of ITSector.Site.Core.Controllers.HomeController 4.) Container.GetInstance(ITSector.Site.Core.Controllers.HomeController)

内部异常是: 指定的类型不是接口 参数名称:interfaceToProxy 使用stacktrace:

The inner exception is: Specified type is not an interface Parameter name: interfaceToProxy With the stacktrace:

at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, Object target, ProxyGenerationOptions options, IInterceptor[] interceptors)
   at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithTarget[TInterface](TInterface target, IInterceptor[] interceptors)
   at lambda_method(Closure , IBuildSession , IContext )

我使用Structure.MVC5.Update nuget作为依赖项解析器. 谁能给我任何有关如何实现它以拦截控制器方法调用的提示.

I use the Structure.MVC5.Update nuget as the Dependency Resolver. Can anyone give me any hint on how to implement it to intercept calls on controller methods.

谢谢.

推荐答案

StructureMap期望在For<T>()方法中使用接口,但是您正在传递它HomeController,这是一个具体类.

StructureMap is expecting an interface in the For<T>() method, but you're passing it HomeController, which is a concrete class.

您有两种选择可以使其正常运行.您可以使用For<IController>()LoggerInteceptor附加到所有控制器.如果仅要将记录器附加到某些控制器,则可以为记录的控制器创建一个新接口,例如For<ILoggedController>(),并确保所需的控制器继承自ILoggedController.

You have a couple of options to get it working. You can attach your LoggerInteceptor to all controllers with For<IController>(). If you only want to attach the logger to some of your controllers, you can create a new interface specifically for the logged controllers, like For<ILoggedController>(), and ensure the desired controllers inherit from ILoggedController.

这篇关于使用StructureMap.DynamicInterception进行面向方面的编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆