Understanding Modularity | Development Activities | Deployment Activities

Modularity QuickStart

The Modularity QuickStart illustrates the key modularity components in a Web client solution.

Building and Running the QuickStart

The QuickStart ships as source code, which means you must compile it before running it. This QuickStart does not require any additional setup.

To build and run the QuickStart
  1. Open the solution file ModularityQuickstart (VSTS Tests).sln (this solution contains unit tests for Visual Studio) or ModularityQuickstart.sln (this solution does not contain unit tests).
  2. On the Build menu, click Rebuild Solution.
  3. Press F5 to run the QuickStart.

Implementation Notes

The QuickStart contains the following modules:
  • A business module named Customers. This module contains two views that implement a customer approval process. The Web site folder Customers contains the views.
  • A business module named Shell. This module provides the implementation of the global Web site pages. The global pages are those that reside in the root of the Web site (such as the default page). The module contains the visual styles for the Web site. It also registers two global services, an ISiteMapBuilderService implementation and an IAuthorizationService implementation.
  • A foundational module named Navigation. This module registers the service named RedirectNavigationService. The application uses this service to perform navigation between pages. Figure 1 illustrates the solution structure of the QuickStart.
Figure 1
Modularity QuickStart solution structure

The Customers module uses the INavigationService service to perform transitions between views. The Navigation module contains the INavigationService implementation. This means the Customers module has a dependency on the Navigation module. The Customers module also uses the ISiteMapBuilderService, provided by the Shell module, to register site map nodes. This means the Customers module has a dependency on the Shell module. These dependencies are expressed in the module definition in the Web.config file of the Customers module, as shown in the following XML.

  <module name="Customers" assemblyName="Customers" virtualPath="~/Customers">
      <dependency module="Shell" />
      <dependency module="Navigation" />

To register the RedirectNavigationService as a global service, the module initializer class in the Navigation module contains the following code.

protected virtual void AddGlobalServices(IServiceCollection globalServices)
    globalServices.AddNew<RedirectNavigationService, INavigationService>();

The CustomersController class in the Customers module uses the ServiceDependency attribute to obtain a reference to the INavigationService, as shown in the following code (taken from the CustomersController class).

public CustomersController([ServiceDependency] INavigationService navigationService)
    _navigationService = navigationService;

The CustomersController class does not reference the concrete type of the INavigationService implementation. ObjectBuilder provides the INavigationService instance to the class. This allows you to easily replace the service implementation (for example, to use mock service implementation in your unit test).

To register site map nodes, the Customers module uses the ISiteMapBuilderService (registered by the Shell), as shown in the following code.

protected virtual void RegisterSiteMapInformation(ISiteMapBuilderService siteMapBuilderService)
    SiteMapNodeInfo moduleNode = new SiteMapNodeInfo("Customers", "~/Customers/ApproveCustomerView.aspx", "Approve Customer");

The Customers module registers the site map node named Approve Customer that appears in the Web site user interface, as shown in Figure 2.
Figure 2
Approve Customer site map node registered by the Customers module

The QuickStart includes unit tests for the Customers and the Navigation modules.

Understanding Modularity | Development Activities | Deployment Activities

Last edited Jan 17, 2008 at 1:34 PM by siacomuzzi, version 2


No comments yet.