Export (0) Print
Expand All

Container and Services

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 Composite Application Library is designed to support other dependency injection containers. Core services, such as the ModuleLoader service, are container agnostic. They use the Composite Application Library container or IContainerFacade interface for resolving, instead of directly accessing the containers. The Composite Application Library provides the UnityContainerAdapter, which is a Unity-specific implementation of this interface. This container is registered by the UnityBootstrapper.

IContainerFacade

The following code shows the IContainerFacade interface.

public interface IContainerFacade
{
    object Resolve(Type type);
    object TryResolve(Type type);
}

You can see that IContainerFacade is only used for resolving and not for registration.

The ModuleLoader uses IContainerFacade for resolving the module during module loading, as shown in the following code.

IModule module = (IModule)containerFacade.Resolve(type);
module.Initialize();

UnityContainerAdapter

The following code shows the implementation of the UnityContainer.

public class UnityContainerAdapter : IContainerFacade
{
    private readonly IUnityContainer _unityContainer;

    public UnityContainerAdapter(IUnityContainer unityContainer)
    {
        _unityContainer = unityContainer;
    }

    public object Resolve(Type type)
    {
        return _unityContainer.Resolve(type);
    }

    public object TryResolve(Type type)
    {
        object resolved;

        try
        {
            resolved = Resolve(type);
        }
        catch
        {
            resolved = null;
        }

        return resolved;
    }
}

The Resolve method calls to the underlying container, except for TryResolve, which Unity does not support. This method returns an instance of the type to be resolved if it has been registered; otherwise, it returns null.

Considerations for Using IContainerFacade

IContainerFacade is not meant to be the general-purpose container. Containers have different semantics of usage, which often drives the decision for why that container is chosen. Bearing this in mind, the Stock Trader RI uses Unity directly instead of using the IContainerFacade. This is the recommend approach for your application development.

In the following situations, it may be appropriate for you to use the IContainerFacade:

  • You are an independent software vendor (ISV) designing a third-party service that needs to support multiple containers.
  • You are designing a service to be used in an organization where they use multiple containers.

Composite Application Library Services

Applications based on the Composite Application Library are composed through a set of services that the application consumes. These services are injected through the container. In addition to these core services, you may have application-specific services that provide additional functionality as it relates to composition.

Core Services

The following table lists the core non-application specific services in the Composite Application Library.

Service interface

Description

IModuleEnumerator

Enumerates the modules in the system. The Composite Application Library provides several different enumerators. For more information, see the Module technical concept.

IModuleLoader

Loads and initializes the modules.

IRegionManager

Registers and retrieves regions, which are visual containers for layout.

IEventAggregator

A collection of events that is loosely coupled between the publisher and the subscriber.

ILoggerFacade

A wrapper for a logging mechanism. The RI uses the Enterprise Library Logging Application Block. This allows you to choose your own logging mechanism.

IContainerFacade

Allows the Composite Application Library to access the container. If you want to customize or extend the library, this may be useful.

Application-Specific Services

The following table lists the application-specific services used in the Stock Trader RI. This can be used as an example to understand the types of services your application may provide.

Services in the Stock Trader RI

Description

IMarketFeedService

Provides real-time (mocked) market data. The PositionSummaryPresentationModel updates the position screen based on notifications it receives from this service.

IMarketHistoryService

Provides historical market data used for displaying the trend line for the selected fund.

IAccountPositionService

Provides the list of funds in the portfolio.

IOrdersService

Handles persisting submitted buy/sell orders.

INewsFeedService

Provides a list of news items for the selected fund.

IWatchListService

Handles when new watch items are added to the watch list.


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.

Show:
© 2014 Microsoft