我有以下代码:
_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对其进行装饰。
现在这工作正常,因为拦截器本身没有依赖项。
但鉴于以下情况:
public class LoggingInterceptor : IInterceptor
{
public LoggingInterceptor(ILogger logger)
{
我将如何在 StructureMap 中进行接线?