Logging using Interceptors in Windsor Container
The Windsor container gives you a provision of adding behavior to components without having to change the components implementation. For example if you want to log whenever a method is called through your this particular component and add behavior when this component is called. Lets see how logging can be achieved for the CustomerService component.
First thing is to create a LogInterceptor.
Here we are implementing the Intercept method of the IInterceptor interface. We are just getting the method name and logging it before the method is invoked and after its completion.
Here is the CustomerService class.
The GetCustomers method just calls the DAO object to get a list of customers. Next we define the components in the services.config file so that the Interceptor is injected at runtime.
Here we are adding a interceptor to the CustomerService class after defining the Interceptor.
Thats that. Now whenever the method is called for this particular component, it is automatically logged.
Comments