This project is read-only.

Composition Containers

A composition container is a run-time container for services and managed objects. The Composite Web Application Block uses composition containers to create instances of, and manage lifetimes of, both shared and independent components. A composition container keeps references to the components it creates, which prevents them from being disposed and collected, even when no other object has a reference to the component.
Every Web Client Software Factory application has a single root composition container. This root container is used to create shared components. The application block also creates a composition container for every business module. The WebClientApplication class creates the root composition container when the application starts, and then it creates a composition container for each business module. The root composition container has access to the collection of module composition containers, and each module composition container can access the root composition container, as illustrated in Figure 1.
Figure 1
Application composition container hierarchy in application state.

The CompositionContainer and ServiceCollection classes both use an ObjectBuilder locator (IReadWriteLocator) and lifetime container (ILifeTimeContainer) to support the discovery and lifetime management of the objects they contain. The locator acts as a dictionary that maps instance names to objects. In the following code example, a module requests a service of type IAuthorizationRulesService. The ServiceCollection class (available as the Services property of the root composition container) uses the locator to find the requested service.

IAuthorizarionRulesService authorizationRulesService = rootContainer.Services.Get<IAuthorizarionRulesService>(); 

The lifetime container keeps object references in use and prevents the objects from being garbage collected until the lifetime container is disposed.

Last edited Nov 20, 2007 at 1:15 PM by ejadib, version 2


No comments yet.