【发布时间】:2012-12-07 16:33:10
【问题描述】:
我有以下代码:
_container = new Container(x => x.AddRegistry<ManagerRegistry>());
-
public class ManagerRegistry : Registry
{
public ManagerRegistry()
{
var proxyGenerator = new ProxyGenerator();
For<IPersonManager>()
.EnrichAllWith(t => proxyGenerator.CreateInterfaceProxyWithTarget(
t, new AuthenticationInterceptor()))
.Use<PersonManager>();
}
}
-
public class AuthenticationInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
if (!HttpContext.Current.User.IsInRole("Monkey"))
throw new Exception("Only monkeys allowed!");
invocation.Proceed();
}
}
它拦截创建StructureMap中的依赖项,并装饰它使用DynamicProxy。
现在这工作正常,因为 interceptor 本身没有 依赖项。
但鉴于以下情况:
public class LoggingInterceptor : IInterceptor
{
public LoggingInterceptor(ILogger logger)
{
如何在 StructureMap 中连接?
【问题讨论】:
-
如果你遇到这个问题,你可能一直在寻找这个问题:stackoverflow.com/questions/43352278/…
标签: c# .net dependency-injection structuremap castle-dynamicproxy