Skip to content

Instantly share code, notes, and snippets.

@lukeschafer
Created June 24, 2014 22:44
Show Gist options
  • Save lukeschafer/1f3e30b3537994a073e8 to your computer and use it in GitHub Desktop.
Save lukeschafer/1f3e30b3537994a073e8 to your computer and use it in GitHub Desktop.
Nimbus Autofac Interceptor Workaround
public static class InterceptorExtensions
{
public static ContainerBuilder WithInbound<TInterceptor>(this ContainerBuilder builder, Func<IComponentContext, TInterceptor> factory = null)
where TInterceptor : IInboundInterceptor
{
if (factory != null)
builder.Register(factory).AsSelf().As<IInboundInterceptor>().Named<TInterceptor>(typeof (TInterceptor).FullName);
else
builder.RegisterType<TInterceptor>().AsSelf().As<IInboundInterceptor>().Named<TInterceptor>(typeof(TInterceptor).FullName);
return builder;
}
public static ContainerBuilder WithOutbound<TInterceptor>(this ContainerBuilder builder, Func<IComponentContext, TInterceptor> factory = null)
where TInterceptor : IOutboundInterceptor
{
if (factory != null)
builder.Register(factory).AsSelf().As<IOutboundInterceptor>().Named<TInterceptor>(typeof(TInterceptor).FullName);
else
builder.RegisterType<TInterceptor>().AsSelf().As<IOutboundInterceptor>().Named<TInterceptor>(typeof(TInterceptor).FullName);
return builder;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment