Scenario: have a WPF application based on custom MVVM + Broker + Castle, the users told us that some operations took long time to accomplish and they want a wait cursor on the application.
Resolution: Since all long operations are triggered with event handled by a Broker system, the obvious solution is an interceptor
1: public class WaitCursorInterceptor : IInterceptor
3: private IWpfSystem _wpfSystem;
5: public WaitCursorInterceptor(IWpfSystem wpfSystem)
7: _wpfSystem = wpfSystem;
10: public void Intercept(IInvocation invocation)
12: using (_wpfSystem.SetWaitCursor())
This depends on the IWpfSystem interface that has this function to change the cursor of the application
1: public DisposableAction SetWaitCursor()
3: Mouse.OverrideCursor = Cursors.Wait;
4: return new DisposableAction(() => Mouse.OverrideCursor = null);
Now you only need to wire up everything adding the interceptor on the IBroker interface.
11: .Interceptors(new InterceptorReference(typeof(WaitCursorInterceptor))).Anywhere);
Now every call to broker function pass through the interceptor that automatically set the cursor to wait. Then users told us that some views take a long time to open and they want the cursor to appear when a new view waits to appear.
Since all view are created/managed by the navigator, you only need to write this.
4: .Interceptors(new InterceptorReference(typeof(WaitCursorInterceptor))).Anywhere);
Add the same interceptor on the INavigator interface, and the game is done.