0
現在,我正在裝飾我的StructureMap4映射的類型,例如IFormsAuthenticationProvider
與CastleMap生成的代理在StructureMap4註冊表中具有tryCatchInterceptor
。例如:使用castle裝飾結構圖4返回的所有實例。動態代理
public class AuthenticationRegistry : Registry
{
public AuthenticationRegistry()
{
var proxyGenerator = new ProxyGenerator();
var tryCatchInterceptor = new TryCatchInterceptor();
For<IFormsAuthenticationProvider>().Use<FormsAuthenticationProvider>()
.DecorateWith(x => proxyGenerator.CreateInterfaceProxyWithTarget<IFormsAuthenticationProvider>(x, tryCatchInterceptor));
}
}
public class TryCatchInterceptor : IInterceptor
{..}
但正如你所看到的,我必須指定裝飾方法中的類型。因此,必須爲所有IType-> Type定義類似的裝飾器,此時代碼將變得重複。
問題:有沒有辦法在一個共同的地方做到這一點,對於所有類型沒有重複?