Webscale architecture, Actors, CQRS, PowerShell, DevOps, Infrastructure as Code, Continuous Delivery
Thursday, February 18, 2010
Whitepaper - Designing Modular Smart Clients using Composite Client Application Guidance
Sunday, December 14, 2008
Composite WPF Guidance - Part 10 Modules (Dynamic Loading)
Configuration Driven Module: LoadingIn this style of loading, modules are located by the ConfigurationModuleEnumerator, which scans the App.config file for modules and module dependencies.
protected override IModuleEnumerator GetModuleEnumerator()
{
ConfigurationStore store = new ConfigurationStore();
return new ConfigurationModuleEnumerator(store);
}
App.Config file entries
{ return new DirectoryLookupModuleEnumerator(@".\"); }
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));}
Thursday, December 11, 2008
Composite WPF Guidance – Part 8 (Creating a Shell)
Implementing a Shell consists of creating a WPF window which includes defining several ItemsControls that are identified as regions for modules to add their views to.
The Shell contains a Presenter and is an implementation of the IShellView interface.
The IShellView contains a method signature to launch the Shell form.
void LaunchShell();
The LaunchShell method is called by a BootStrapper to launch the shell form.
Tuesday, December 9, 2008
Composite WPF Guidance – Part 7 (Events)
As shown in the figure above the real work of connecting publishers and subscribers is done by the CompositeWpfEvent class. This is the only implementation of the EventBase class that comes out of the box in the Composite Application Library. This class maintains the list of subscribers and handles event dispatching to the subscribers.
Composite WPF Guidance – Part 6 (Commands)
Use of Delegation and Composition overcomes this issue.
In delegation a command is used that delegates off its handling logic, either through events or delegates where it can be handled externally by a class such as a presenter, service, controller, and so on. This provides the benefit of not having to put any code in the code behind. The command requires two handlers: one for the Execute method and one for the CanExecute method. Whenever the Execute or CanExecute methods are called on the command, the handlers are called either through the event being raised or the delegate being invoked.
The DelegateCommand in CAL allows delegating the commanding logic instead of requiring a handler in the code behind. It uses a delegate as the method of invoking a target handling method.
The DelegateCommand uses its delegate to invoke a CanExecute method or Execute method on the target object when the command is invoked.
A composite command delegates off its handling logic to a set of child commands. The composite command needs to provide a way for the child commands to be registered. Executing the composite command executes the children. The composite commands CanExecute returns false, unless all the children return true. The CompositeCommand class contains a RegisterCommand method to register the child commands.
The figure below shows the relationship between a CompositeCommand and DelegateCommand.
Composite WPF Guidance – Part 5 (View Layout)
- View Injection
- View Discovery
In View Discovery the modules register their views (or presenters) in a central location, such as in the container, using a well-known interface. In CAL each module constructor accepts an instance of IUnityContainer which can be used to register presenters using the IUnityContainer RegisterType
Monday, December 8, 2008
Composite WPF Guidance - Part 4 (Patterns)
Supervising Controller. This pattern, a variant of the Model-View-Presenter pattern, separates the responsibilities for the visual display and the event handling behavior into different classes named, respectively, the view and the presenter, and permits using data binding to enable direct communication between the view and the model.
Presentation Model. This pattern, a variant of the Model-View-Presenter pattern, supplements a façade on the model with UI-specific state and behavior that is easy to consume from the view.
Wednesday, December 3, 2008
Composite WPF Guidance - Part 3 (Patterns)
The Inversion of Control (IoC) pattern is used to enable extensibility in a class or framework. Inversion of Control (IoC) means that objects do not create other objects on which they rely to do their work. Instead, they get the objects that they need from an outside source (for example, an xml configuration file).
In Composite Application Library the container is provided by implementing the IContainerFacade interface. The above mentioned diagram explains the IoC implementation in CAL.
The Service Locator pattern is a form of the Inversion of Control pattern. It allows classes to locate specific services they are interested in without needing to know who implements the service. Frequently, this is used as an alternative to dependency injection, but there are times when a class will need to use service location instead of dependency injection, such as when it needs to resolve multiple implementers of a service. In the Composite Application Library, this can be seen when ModuleLoader service resolves individual IModules.
Tuesday, December 2, 2008
Composite WPF Guidance - Part 2 (Patterns)
- Seperated Interface and Plug In pattern
- Inversion Of Control
- Service Locator
- Command
- Adapter
- Seperated Presentation
- Event Aggregator
- Facade etc
I will explain the use of these patterns in the Composite WPF development using CAL and their significance in the forthcoming articles.
Seperated Interface and Plug In pattern: The ability to locate and load modules at run time encouraging a more loosely coupled application development using CAL is enabled by the Seperated Interface and plug in pattern.
In CAL the quality of its design is improved by reducing the coupling between the system's parts. This is acheived by grouping the classes into packages and controlling the dependencies between them. However, you can invoke methods in other packages by defining an interface in one package but implement it in another. This way a client that needs the dependency to the interface can be completely unaware of the implementation. In CAL each module implements the IModule interface which provides a good plug point for Gateway. The below figure shows the seperated interface implementation in CAL.
Plug In pattern allows the concrete implementation of a class to be determined at run time to avoid requiring recompilation due to which concrete implementation is used or due to changes in the concrete implementation. In the Composite Application Library, this is handled through the DirectoryLookupModuleEnumerator, ConfigurationModuleEnumerator, and the ModuleLoader. The figure below describes the plugin implementation in CAL.
We will look into the other patterns in the following series in CAL.
Monday, December 1, 2008
Composite WPF Guidance - Part 1
The composite WPF application created using CAL will use the Unity Extensions for Composite Application Library and the Unity Application Block. These are built on the .NET Framework 3.5.
The architecture the Composite Application Library as mentioned below consists of a shell application that defines regions for hosting content with views and services offered by multiple modules—possibly dynamically loaded. Underlying the application, and the Composite Application Library, is a service layer to provide access to the application services based on the Composite Application Library
Most of the components in the diagram have the same functionality or definition as in CAB.
Shell is the top level container window to host user interface components.
Any logic for the shell is handled by the shell presenter. This follows the separated presentation pattern* and helps separate the display of content from the user interface logic.
Regions are placeholders for content and host visual elements in the shell. These can be located by other components through the RegionManager to add content to those regions. Regions can also be used in module views to create discoverable content placeholders. Regions replace the Workspaces in CAB.
Modules represent a Use Case and have sets of views and services, frequently logically related, that can be independently developed, tested, and optionally deployed. Modules are discovered and loaded, in the Composite Application Library by a process known as module enumeration and module loading.
Views are responsible for displaying content on the screen. The views logic are handled by implementing appropriate design patterns for separations of concerns. Typically, this involves some type of binding-oriented design pattern, such as Supervising Controller* or Presentation Model*. Views are created to take full advantage of the data binding features of WPF.
Communication within the modules should not require hard dependencies on one another. The Composite Application Library provides mechanisms to do this with the CompositeCommand and EventAggregator. The composite command is a strategy to combine the execution of commands. This allows the command invoker to interact with a single command that affects multiple commands. EventAggregator is used in views that need to send an event to other views or components and do not require a response. Multiple components can publish an event, and multiple subscribers can receive the event.
The application and modules expose services for their own and shared use. These are exposed through a service container that locates and, often, constructs the services. By default, the Composite Application Library uses the Unity container for this service location.
I will explain in detail about the components used in CAL and their functionality in detail in the upcoming series.