Search This Blog

Thursday, January 17, 2013

A trick for the XAF application server

As you probably know, the Application Server creates its own GUI-less XafApplication descendant - ServerApplication. When working with Application Server, you should be aware of a very important requirement desribed at http://documentation.devexpress.com/#Xaf/CustomDocument3438:

The ServerApplication.Modules collection. It should contain modules that are directly referenced by your client application. To see which client application modules are required, refer to the InitializeComponent method code in your WinApplication/WebApplication descendant. There is no need to add modules that are indirectly added to your client application (i.e., modules that are added to your custom modules).

In this blog post, I would like you to show you how to comply with this requirement without having to add extensive references to all the extra modules used in your client apps, and having to write a great number of lines like: serverApplication.Modules.Add(new DevExpress.ExpressApp.XXX.XXXModule());

My goal is to save you time in adding these references (the "Add Reference | .NET"  dialog has always been and still is one of the weakest places in Visual Studio prior to VS2012) and writing unfamiliar code in Visual Studio. Technically, I want to achieve this by cutting this initialization code to just a few lines in the application server project:

...
// Add your client application's modules to the ServerApplication.Modules collection here. 
List<ModuleBase> list = new List<ModuleBase>(new Solution2.Win.Solution2WindowsFormsApplication().Modules);
foreach(ModuleBase item in list) {
    if(!serverApplication.Modules.Any<ModuleBase>(m => m.GetType() == item.GetType())) {
        serverApplication.Modules.Add(item);
    }
}
...

The trick is to just reference two client apps assemblies (YourSolutionName.Win and YourSolutionName.Web) and then instantiate these the XafApplication descendants to grab their Modules list.

Of course, it can be achieved more easily, and we have the corresponding request in our TODO list: http://www.devexpress.com/Support/Center/Issues/ViewIssue.aspx?issueid=S38219 Feel free to share your ideas and suggestions on how to make this more usable for developers.

2 comments:

  1. We use the trick you mention (instantiate the client apps and grab their modules) and it works like a charm.

    ReplyDelete
  2. Thank you for posting your results here, Daniel!

    ReplyDelete