Skip to content

Rzpeg/CodeCop.Setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodeCop.Setup

Fluent API Wrapper for CodeCop

What?

A Fluent API wrapper package for CodeCop, providing an alternative way of configuring interceptors using the code.

Why ?

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.

How ?

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.

License

The package is licensed under under The MIT License (MIT).

About

Fluent API for CodeCop

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages