首页 新闻 会员 周边

unity aop如何只对想要拦截的方法进行拦截,而不是拦截整个类

1
[已关闭问题] 关闭于 2016-01-05 13:36

首先看配置:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,Microsoft.Practices.Unity.Configuration"/>
  </configSections>
  <unity xmlns="http://schemas.microsoft.com/practces/2010/unity">
    <sectionExtension type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationExtension, Microsoft.Practices.Unity.Interception.Configuration"/>
    
    <typeAliases>
      <typeAlias alias="transient" type="Microsoft.Practices.Unity.TransientLifetimeManager, Microsoft.Practices.Unity"/>
    </typeAliases>
    
    <alias alias="ExceptionLogBehaviorName" type="AppTest.ExceptionLogBehavior,AppTest"></alias>
    
    <container>
      <extension type="Interception"/>
      <register type="AppTest.IDictionaryService, AppTest" mapTo="AppTest.DictionaryService, AppTest">
        <interceptor type="InterfaceInterceptor"/>
        <interceptionBehavior type="ExceptionLogBehaviorName"/>
        <lifetime type="transient"></lifetime>
      </register>
    </container>
  </unity>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

这样的话就是对IDictionaryService里的任何一个方法都进行ExceptionLogBehavior

拦截。

假如接口IDictionaryService有两个方法:MethodOne、MethodTwo,我只想对MethodTwo进行拦截,怎么配置,谢谢。

50
问题补充:

大神何在?速速过来!

屌丝大叔的笔记的主页 屌丝大叔的笔记 | 初学一级 | 园豆:2
提问于:2015-12-28 19:45
< >
分享
所有回答(1)
0

给方法添加属性,然后在拦截方法里面判断该方法是否有该属性标记

chenxizhaolu | 园豆:202 (菜鸟二级) | 2020-02-21 21:23
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册