Skip to content

Repository files navigation

Autofac.Extras.DynamicProxy

Interceptor and decorator support for Autofac via Castle DynamicProxy.

Build status codecov NuGet

Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.

Quick Start

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.

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.

About

Interceptor and decorator support for Autofac IoC via Castle DynamicProxy

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages