Skip to content

Helpers for creating interceptors with castle core and Unity Container

Notifications You must be signed in to change notification settings

christianarg/CastleInterceptHelpers

Repository files navigation

CastleInterceptHelpers

Helpers for creating interceptors with castle core and Unity Container

Usage

Global interceptors

// Create container
IUnityContainer unityContainer = new UnityContainer();
unityContainer.RegisterType<IMyFooService, MyFooService>(); 
// Call InterceptionHelper.InterceptContainer with your interceptors as arguments. This will return a new child container whose all registration will be intercepted
unityContainer = InterceptionHelper.InterceptContainer(unityContainer, new IInterceptor[] { new MyInterceptor() });

Attribute Interceptors

[InterceptWith(typeof(MyInterceptor))]  // decorate your class like this
public class MyFooServiceWithAttributeInterceptor : IMyFooService
{
  public void Execute(){ }
}

// Then initialize the interception:

// Create container
IUnityContainer unityContainer = new UnityContainer();
unityContainer.RegisterType<IMyFooService, MyFooService>(); 
// Call InterceptionHelper.InterceptContainer This will return a new child container whose all registration will be intercepted
unityContainer = InterceptionHelper.InterceptContainer(unityContainer, new IInterceptor[] { });  // In this example I'm not passing global interceptors but you can use both global and attribute interceptors

About

Helpers for creating interceptors with castle core and Unity Container

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages