I have the following code:
_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();
}
}
It interceps the creation of a dependency in StructureMap, and decorates it using DynamicProxy.
Now this works fine, because the interceptor has no dependencies itself.
But given the following:
public class LoggingInterceptor : IInterceptor
{
public LoggingInterceptor(ILogger logger)
{
How would I go about wiring that up in StructureMap?