Scenario
This example demonstrates how to create custom XAF modules with custom business objects and logic that would work with separate databases. These modules do not depend on each other and thus can be reused in other applications as a whole.
Steps to implement
0. Create a new XAF solution using one of predefined project templates;
1. Add two XAF modules into this solution using the DevExpress vXX.X XAF Module project template;
2. Add required persistent classes into these modules as shown in the ClassLibraryN/PersistentClassN.xx files of this example solution;
3. Add service ModuleInfo classes into these modules as shown in the ClassLibraryN/ModuleInfoN.xx files of this example solution;
4. Override the Setup(XafApplication application) methods of your ModuleBase descendants (see the YourModuleName/Module.xx files) as shown in the ClassLibraryX/XafModuleN.xx files of this example solution;
5. Build the solution, invoke the Module Designer for the platform-agnostic module (YourSolutionName.Module/Module.xx), and drag the created custom modules from the Toolbox:
Alternatively, you can add the same modules via the Application Designer invoked for the executable projects (as demonstrated in this example).
6. Declare connection strings in the configuration files of your application as shown in the TwoXpoModelsForDifferentDatabases.Web\Web.config and TwoXpoModelsForDifferentDatabases.Win\App.config files (see ConnectionStringDatabaseX under the <connectionStrings/> element). These connection strings are used in the modules via the ConfigurationManager.ConnectionStrings API, but you can always modify the way your modules obtains this data.
Important notes
1. Each module has a single static XPObjectSpaceProvider instance, which is initialized only once during the application life cycle.
2. Each ModuleUpdater class checks the ObjectSpace property to determine whether it is valid to create initial data of a certain type from this module.
See also:
How to prevent altering the legacy database schema when creating an XAF application