Skip to content

autofac/Autofac.Extras.DynamicProxy

Repository files navigation

Autofac.Extras.DynamicProxy

Interceptor and decorator support for Autofac via Castle DynamicProxy.

Build status codecov

Autofac on Stack Overflow

Get Packages

You can get Autofac.Extras.DynamicProxy by grabbing the latest NuGet packages. If you're feeling adventurous, continuous integration builds are on MyGet.

Release notes are available on GitHub.

Get Help

Need help with Autofac? We have a documentation site as well as API documentation. We're ready to answer your questions on Stack Overflow or check out the discussion forum.

If you find a bug with Autofac.Extras.DynamicProxy please file it in that repo.

Get Started

First, create your interceptor:

public class CallLogger : IInterceptor
{
  TextWriter _output;

  public CallLogger(TextWriter output)
  {
    _output = output;
  }

  public void Intercept(IInvocation invocation)
  {
    _output.Write("Calling method {0}.", invocation.Method.Name);
    invocation.Proceed();
    _output.WriteLine("Done: result was {0}.", invocation.ReturnValue);
  }
}

Then register your type to be intercepted:

var builder = new ContainerBuilder();
builder.RegisterType<SomeType>()
       .As<ISomeInterface>()
       .EnableInterfaceInterceptors();
builder.Register(c => new CallLogger(Console.Out));
var container = builder.Build();
var willBeIntercepted = container.Resolve<ISomeInterface>();

You can read more details in the documentation.

Contributing / Pull Requests

Refer to the Contributor Guide for setting up and building Autofac source.

You can also open this repository right now in VS Code.