Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

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. The following procedure describes how to build and run the QuickStart.

To build and run the QuickStart

  1. Download and extract the source code.
  2. Open the solution file ModularityQuickstart (VSTS Tests).sln (this solution contains unit tests for Visual Studio).
  3. On the Build menu, click Rebuild Solution.
  4. 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 Customers Web site folder 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 7

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="ModularityQuickstart.Customers" virtualPath="~/Customers">
      <dependency module="Shell" />
      <dependency module="Navigation" />

The following XML code demonstrates how the Shell and other foundational modules that do not have their own .config files are registered with the Web.config file.

  <module name="Shell" assemblyName="ModularityQuickstart.Shell" virtualPath="~/"/>
  <module name="Navigation" assemblyName="ModularityQuickstart.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;


Note: 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 8

Approve Customer site map node registered by the Customers module


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