castle windsor - How to register an interface for interceptions -
i want register interface like: iinterceptingaware
, classes implement interface interceptor class used.
public class interceptorclass : iinterceptor { public void intercept(iinvocation invocation) { // work } } public class foo : iinterceptingaware { } public class bar : iinterceptingaware { }
how setup castle windsor this?
using (var container = new windsorcontainer()) { container.register( component.for<myinterceptorclass>(), classes.fromthisassembly() .basedon<iinterceptingaware>() .withservicedefaultinterfaces() .configurefor<iinterceptingaware>(c => c.interceptors<myinterceptorclass>()) ); var foo = container.resolve<foo>(); foo.test(); var bar = container.resolve<ibar>(); bar.test(); } console.readline();
keep in mind interceptor requires @ least virtual methods on target class, better target class should implement interface in order have interceptor working on contract.
said so, foo
class should @ least have method named test
marked virtual
while bar
should implement ibar
:
public interface ibar { void test(); }
Comments
Post a Comment