Home

Van Nguyen edited this page May 2, 2016 · 10 revisions

Enable interceptors with Autofac

For now, you will need Autofac and Castle.Core. After add these 2 nuget packages, simply call EnableInterceptors() on type registration you want to intercept:

var builder = new ContainerBuilder();
builder.RegisterModule(new FlatwhiteCoreModule());
builder.RegisterType<UserService>()   
    .As<IUserService>()  
    .EnableInterceptors();

Or you can apply for all registrations by using FlatwhiteBuilderInterceptModule

var builder = new ContainerBuilder();
builder.RegisterModule(new FlatwhiteCoreModule());
builder.RegisterType<BlogService>()
    .AsImplementedInterfaces()
    .AsSelf();

// Register other types normally
...

// Then register FlatwhiteBuilderInterceptModule at the END before building the Container
builder.RegisterModule<FlatwhiteBuilderInterceptModule>();            
var container = builder.Build();

More info about built-in attributes:

Flatwhite.ExceptionFilterAttribute

Flatwhite.MethodFilterAttribute

Flatwhite.OutputCacheAttribute

Flatwhite.RevalidateAttribute

Flatwhite.NoInterceptAttribute

Using Flatwhite with WebAPI

Flatwhite.WebAPI