New in This Guidance Bundle

This release of the Composite Web Application Block is an update to the application block included in the Web Client Software Factory - June 2007 release and contains the following changes:
  • The dependency injection implementation now provides dependency injection support for classes other than the Page class, such as user controls, master pages, or web services.With this implementation, you must explicitly invoke BuildItemWithCurrentContext.
ASP.NET constructs pages and user controls at different points in the pipeline. Using an explicit invocation of the BuildItemWithCurrentContext method provides a consistent point in the ASP.NET page life cycle where the dependency injection for both pages and user controls will occur. However, this also means that a Web page must initiate its own dependency injection.

You can see the dependency injection code in new base classes in the Microsoft.Practices.CompositeWeb.Web.UI namespace. The following code is from the MasterPage class.

public class MasterPage : System.Web.UI.MasterPage
  protected override void OnInit(EventArgs e)
  • The application block now contains a StateDependency attribute. You can use this attribute to inject a StateValue object into constructors, methods, and properties (in the previous version you could only inject StateValue objects into public fields).
class SampleClass
  private StateValue<string> _myStringValue;
  public SampleClass([StateDependency("stringKey")] StateValue<string> myStringValue)
    _myStringValue = myStringValue;
  public string MyStringValue
    get { return _myStringValue.Value; }
  • The extensions to ObjectBuilder are now part of the Composite Web Application Block project. This was done to reduce the number of dependencies needed to use the application block. (No changes were needed in the extensions to support the new dependency injection.)
  • You can now use type mapping to associate one type (type “A”) with another type (type “B”) for dependency injection purposes. When your code uses the dependency injection attributes for type A, ObjectBuilder will instantiate and inject an object of type B. For example, in the following code, the ContactListModel type is mapped to the IContactListModel interface.
public override void Load(CompositionContainer moduleContainer)
    moduleContainer.RegisterTypeMapping<IContactListModel, ContactListModel>();

After the types are mapped, a class can request an object by the IContactListModel interface, as illustrated in the following code.

public IContactListModel Model
  get { return _model; }
  • You can now register services through configuration. You can register a service as either a module service or global service. To register a service, you create a service element in Web.config file of a module. The following XML is an example of the service element (in this example, the service is registered as a global service).
  <service registerAs="OrdersRepository.Interfaces.Services.ICustomerService, OrdersRepository.Interfaces" type="OrdersRepository.Services.CustomerService, OrdersRepository.Services" scope="Global" />

Last edited Nov 19, 2007 at 8:24 PM by siacomuzzi, version 1


No comments yet.