Fluent API Wrapper for CodeCop
A Fluent API wrapper package for CodeCop, providing an alternative way of configuring interceptors using the code.
The idea is to extend the existing API and to provide a lean alternative for those seeking for a more straightforward way of bootstrapping their hooks.
I also want to add some features missing from the CodeCop, such as (but not limited to) loading hooks from various locations, including databases, files, and assemblies, integrating with your favourite IoC container and the likes.
Everything resolves arround the configuration API.
Setup
.Build()
.InterceptMethodIn<Program>(nameof(DoStuff), Intercept.Before,
ctx =>
{
Console.WriteLine("InterceptOn.Before > DoStuff !");
return null;
})
.InterceptMethodIn<Program>(nameof(DoAnotherStuff), new MyInterceptor())
.Create()
.Activate();
You can also use your favourite IoC container containing registrations for your interceptors (ITypedInterceptor). To do so, install the adapter package (available for Autofac, StructureMap, Unity, Castle.Windsor and Ninject).
Example:
var containerBuilder = new ContainerBuilder();
containerBuilder
.RegisterType<MyInterceptor>()
.As<ITypedInterceptor>();
var container = containerBuilder.Build();
var copAdapter = new CodeCop.Setup.Autofac.AutofacContainerAdapter(container);
Setup
.Build(copAdapter)
.Create()
.Activate();
You can also combine IoC registered interceptors and fluent-api.
Setup
.Build(copAdapter)
.InterceptMethodIn<Program>(nameof(DoStuff), Intercept.Before,
ctx =>
{
Console.WriteLine("InterceptOn.Before > DoStuff !");
return null;
})
.InterceptMethodIn<Program>(nameof(DoAnotherStuff), new MyInterceptor())
.UseInterceptor(new ProgramTypedInterceptor())
.Create()
.Activate();
The sample console application CodeCop.Setup.Demo can be found Here . The documentation file is located in Help folder.
The package is licensed under under The MIT License (MIT).