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

ObjectBuilder Build Plans - BuildPlanStrategy and DynamicMethodPlan for WCSF v2.0 and Unity


The Web Client Software Factory v2.0 Documentation mentions a new ObjectBuilder BuildPlanStrategy for object creation that replaces a number of other strategies that used reflection quite heavily: ConstructorReflectionStrategy, CreationStrategy, PropertyReflectionStrategy, and MethodReflectionStrategy. Unity will also be taking advantage of the DynamicMethodPlan Build Plan, which should provide a lot better performance for object creation in your applications.

 

Build Plans

Per the Web Client Software Factory ( WCSF ) Documentation:

"Build plans are created the first time ObjectBuilder builds an object of a particular type. A build plan is created by using the reflection API to inspect the type definition and then dynamically emitting Microsoft Intermediate Language (MSIL) code. To create the appropriate MSIL code for each type, a chain of strategies is executed. By default, these strategies are the following:"

  • CallConstructorStrategy
  • SetPropertiesStrategy
  • CallMethodsStrategy

The DynamicMethodPlan Build Plan uses the DynamicMethod Class in the .NET 2.0 Framework:

"You can use the DynamicMethod class to generate and execute a method at run time, without having to generate a dynamic assembly and a dynamic type to contain the method. The executable code created by the just-in-time (JIT) compiler is reclaimed when the DynamicMethod object is reclaimed. Dynamic methods are the most efficient way to generate and execute small amounts of code."

 

Composite Web Application Block in Web Client Software Factory v2.0

The Composite Web Application Block ( CWAB ) in WCSF v2.0 takes advantage of the Build Plan for the creation strategy. Again, per the WCSF Documentation:

"Some ObjectBuilder strategies that were used in earlier releases of the Web Client Software Factory were replaced with new strategies that provide improved performance. However, the source code for the replaced strategies can still be found within the Composite Web Application Block source code:"

  • TypeMapping: ContainerAwareTypeMappingStrategy
  • PreCreation: TypeMappingStrategySimplifiedSingletonStrategy
  • Creation: BuildPlanStrategy
  • Initialization: SessionStateBindingStrategy
  • PostInitialization: BuilderAwareStrategy

 

ObjectBuilder Build Plans

 

Unity and Build Plans

Unity IoC is / will also be using Build Plans to improve the performance of object creation.

 

Conclusion

By taking advantage of the DynamicMethod Class in the .NET 2.0 Framework, both the Web Client Software Factory and Unity will improve performance during object creation over the previously used reflection-based strategies.

Hope this helps.

David Hayden


Tags: CompositeWebApplicationBlock, ObjectBuilder, Unity


Topics



Popular Tags



Recent Links