私は次のコードを持っています:
_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でそれを配線するにはどうすればよいですか?