skip to the main content area of this page
Patterns and Practices

 

WCSF and Castle ActiveRecord


The Composite Web Client Automation and Web Client Libary Guidance Bundles in the Web Client Software Factory v2.0 work well with Castle Project's ActiveRecord. You need to adjust where you initialize and register the ActiveRecord Configuration and Business Objects from the guidance provided in the Castle Project ActiveRecord Getting Started Documentation.

Rather than initializing the configuration settings and ActiveRecord Types in the Application_Start Event of your Composite Web Client Application, you will instead perform these functions during the intialization of the business modules or even foundation modules. In this example, we will focus on initialization using business modules.

As a rule of thumb, the business modules should be responsible for registering their own ActiveRecord Types. It is recommended that one create a RegisterActiveRecordTypes Method in each ModuleInitializer that registers the ActiveRecord Types in each business or foundation module. For example, here is an example of registering a Customer ActiveRecord Type in the CustomersModuleInitializer that can be found in a Customers Business Module:

 

public override void Load(CompositionContainer container)

{

    base.Load(container);

 

    RegisterActiveRecordTypes();

    AddGlobalServices(container.Parent.Services);

    AddModuleServices(container.Services);

    RegisterSiteMapInformation(container.Services.Get<ISiteMapBuilderService>(true));

 

    container.RegisterTypeMapping<ICustomersController, CustomersController>();

}

 

private void RegisterActiveRecordTypes()

{

    ActiveRecordStarter.RegisterTypes(new Type[] { typeof(Customer) });

}

 

In this instance we are only creating one ActiveRecord Type - Customer. In your example, you may have more.

 

If we had an Employees Business Module, we would do the same thing if we wanted to register an Employee ActiveRecord Type in the EmployeesModuleInitializer:

 

public override void Load(CompositionContainer container)

{

    base.Load(container);

 

    RegisterActiveRecordTypes();

    AddGlobalServices(container.Parent.Services);

    AddModuleServices(container.Services);

    RegisterSiteMapInformation(container.Services.Get<ISiteMapBuilderService>(true));

 

    container.RegisterTypeMapping<IEmployeesController, EmployeesController>();

}

 

private void RegisterActiveRecordTypes()

{

    ActiveRecordStarter.RegisterTypes(new Type[] { typeof(Employee) });

}

 

Each business module has a dependency on the Shell BusinessModule, which means the ShellModuleInitializer will run first. It is in the ShellModuleInitializer where we will create a method, called InitializeActiveRecordStarter, that will run first and initialize Castle ActiverRecord with the database settings:

 

public override void Load(CompositionContainer container)

{

    base.Load(container);

 

    InitializeActiveRecordStarter();

    AddGlobalServices(container.Parent.Services);

    AddModuleServices(container.Services);

    RegisterSiteMapInformation(container.Services.Get<ISiteMapBuilderService>(true));

}

 

private void InitializeActiveRecordStarter()

{

    ActiveRecordStarter.Initialize(ActiveRecordSectionHandler.Instance);

}

 

Again, this is different from the Getting Started Documentation found on the Castle Project Website to support composite web client applications that use the Microsoft Patterns & Practices Web Client Software Factory. The Getting Started Documention on the Castle Project Website does not take into consideration the composite web client guidance and the use of module initlializer classes found in the WCSF.


Tags: CastleActiveRecord, CompositeWebClientAutomation


Topics



 

Popular Tags



Recent Links