Sunday, December 14, 2008

Composite WPF Guidance - Part 9 Modules (Static loading)

A module in the Composite Application Library is a logical unit in your application. These modules are defined in such a way that they can be discovered and loaded by the application at run time. Because modules are self-contained, they promote separation of concerns in your application. Modules can communicate with other modules and access services through various means. They reduce the friction of maintaining, adding, and removing system functionality. Modules also aid in testing and deployment.

A module in CAL is a class that implements the IModule interface. This interface contains a single Initialize method that is called during the module's initialization process. Module loading in the Composite Application Library is a two-step process:

Static Loading and Dynamic Loading

The module enumerator discovers modules and creates a collection of metadata about those modules. The module loader instantiates the module and calls its Initialize method.

Static Module Loading: In static module loading, the shell has a direct reference to the modules, but the modules themselves do not directly reference the shell. They can be in the same assembly or a different assembly. The benefit of this style of loading over dynamic module loading is that modules are easier to use and debug because they are directly referenced. The disadvantage of static module loading is that you have to add new references to the shell and a line of code to the bootstrapper for each module.

protected override IModuleEnumerator GetModuleEnumerator()
{
return new StaticModuleEnumerator()
.AddModule(typeof(User.UserModule))
.AddModule(typeof(Accounts.AccountModule));}

}

No comments: