Modules | Services

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 solution that uses the Composite Web Application Block 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.

Modules | Services

Last edited Jan 17, 2008 at 3:09 PM by siacomuzzi, version 3


No comments yet.