Ability to add shell services prior to module load

Aug 4, 2010 at 8:30 PM

Today I was looking at the source code for the full SCSF 2010 release and noticed that in CabApplication it provides a virtual AddServices() method which is called prior to doing any module loading. I've been thinking it could be quite nice to have a similar feature in the SmartClientApplication class in the IoC.UI framework.

One possible scenario in my application I'm thinking this could be useful is as follows, the application uses a single form in the shell holding a maximised deckworkspace, all views are then smartparts displayed in this workspace. I wanted to implement a mechanism for dialog boxes similar to the .NET framework MessageBox class but without using that (I dislike that using for example only an "OK" button results in no actual button at all), I've implemented this using a SmartPart with a picturebox covering the full area which on activation captures the current workspace graphic, dims it and displays it in the picturebox, there is then a usercontrol on top of this representing a non-fullscreen error box with message, icon, buttons etc. This gives the appearance of modal functionality in a smartpart without me having to use an actual form and ShowDialog(), of course this makes getting the result a little trickier, for this a delegate can be passed in which will be called with the appropriate DialogResult when the user clicks a button and closes the dialog. I've wrapped all of this up in a service in the shell project with various overloads of a Show() method to mimic MessageBox.Show() and then use this wherever I require a message box.

I can see some scenarios where it may be nice to display a message box from within one of the other modules in the application rather than always passing error messages back to the shell by use of events etc, I have the interface for the service in my Infrastructure.Interfaces project which can obviously be referenced by the modules but since the service itself is in the shell it cannot exist in the service collection at the point the modules load and therefore I can't use it by dependency injection for example. If there was a virtual SmartClientApplication.AddServices() which was called prior to module load I could register this message box service from the shell before the modules load and then inject it in the modules. I could of course move this service out of the shell into a module and ensure that module is loaded before any that use it but since the service is a concrete part of the UI it feels to me like it should remain in the shell with all the views and other concrete UI code.

I may not end up going this way but after seeing the code in the full SCSF it looked quite useful for what would be a very minor change.

Aug 6, 2010 at 3:39 PM

Simple enough.  I've added AddServices tot he latest change set.