One of the coolest new capabilities we're building for Enterprise Library v3 is the Application Block Software Factory. As its name ever-so-subtly suggests, this will be a software factory for building your own application blocks. We'll be including an early drop of this factory in the first preview release of Enterprise Library v3 (soon, I promise!) - but in the meantime this blog is, as always, your best bet for some early details.
First, let me explain why we wanted to include a block factory in Enterprise Library. Right from the start, we built Enterprise Library with the expectation that people would want to extend it - either by building new providers, or by building entire new blocks. But while some types of extensibility are relatively straightforward for developers, things quickly get more and more complex if you want to do things like create strongly typed configuration classes, configuration design assemblies, or your own blocks with factories and provider hierarchies.
In EntLib v1 we included the "Hello World Application Block". While it wasn't hugely popular in enterprise applications (apparently people just aren't building applications that need to provide customized greetings :-), it did serve a useful purpose in providing simple examples showing the common patterns for building your own blocks. In v2 we didn't get time to update the Hello World Application Block, which was a shame as extending Enterprise Library actually got more complex as a result of the decoupling of blocks from configuration and the use of Object Builder. The source of all knowledge on building and extending v2 blocks is Brian's webcasts (here and here), but while the webcasts are a lot fun, it isn't necessarily the best format for helping you do the same.
In the meantime, we've started playing around with software factories, and we think this is a better way of demonstrating and automating routine but sometimes complex tasks when building a particular type of application (or application block, in this case). While the block factory in Enterprise Library won't be quite as in-depth as the standalone software factories, it does follow the same basic approach, and we're pretty excited about the potential for the factory to bring block- and extension-building to the masses.
So what does the factory let you do? This activity diagram shows the key stages to building a block or provider library, and the factory will include one or several recipes to help automate each step:
There are two basic scenarios supported by the factory: creating your own blocks, and creating your own provider libraries. Let's start with the provider library activities. A provider library is an assembly that contains providers for a block that lives somewhere else, for example you may want to create your own assembly with TraceListeners, Filters and Formatters that extend the Logging Application Block.
- Create New Provider Library: This solution template will create an initial project structure for your provider library, including a runtime project, designtime project, unit test projects, and some common references and class files
- Create New Untyped Provider for EntLib Block: This activity includes a number of recipes that make it very easy to build new providers for known Enterprise Library types, eg Logging TraceListeners, Exception Handlers, Caching Backing stores etc. The recipe will prompt for the name and generate a new class that includes all of the necessary interfaces and attributes. The untyped flavor of the recipes uses property bags for configuration, which eliminates the need to build your own configuration classes (runtime or designtime) but comes at the cost of type safety.
- Create New Typed Provider for EntLib Block: This activity includes the same basic set of recipes as for the untyped providers, however they also generate a strongly-typed configuration class and wire this up to the provider. Just add configuration properties!
- Convert Untyped Provider to Typed Provider: What if you created an untyped provider and later on you want to the plunge and make it strongly typed? Have we got a recipe for you!
- Create Typed or Untyped Provider for Your Block: Of course you're not limited to building providers for EntLib blocks. But we'll discuss these activities in the context of building your own block (below).
- Create Provider DesignTime: Once you have a strongly-typed provider, you probably don't feel like editing the XML by hand. The factory includes a recipe that will look at the runtime configuration class and generate some initial configuration design nodes. You'll want to spend some time cleaning it up by hand, for example to add icons, resources and validation, but the recipe does a lot of the dirty work for you.
Now on to building your own application block:
- Create New Block: This will be a solution template that sets up an initial project structure for building your own block, including a runtime project, designtime project, unit test projects, and some common references and class files
- Create New Provider Factory & Base: Most of our application blocks follow a similar pattern involving factories that can generate providers by name, where the actual type of the returned provider is defined in configuration (for example: Database db = DatabaseFactory.CreateDatabase("Sales"); may return an OracleDatabase class or a SqlDatabase class). This recipe sets up abstract base classes and interfaces for a new provider type, as well as a corresponding factory and its associated plumbing.
- Create New Designtime Provider Base Node: This recipe takes a provider base type and generates the key design-time classes to support the complete hierarchy of that type of provider
- Create Typed or Untyped Provider for Your Block: These recipes are much the same as the ones for the known EntLib provider types, except that you'll be prompted for more information such as the base classes and interfaces that correspond to your provider type
- Convert Untyped Provider to Typed Provider: As above
- Create Provider DesignTime: As above
Here's a screenshot showing how some of these recipes will turn up in a solution built with the Application Block template:
Of course, none of this is going to put developers or testers out of work - even with the factory you'll still need to write and test plenty of code. But we're hoping that the factory will make you more productive, make building blocks and providers accessible to more people, and will hopefully result in a lot of weird and wonderful new blocks in the community and in your organization.
As soon as the preview is available, I'll let you know...