This project is read-only.

Configuring DrillBits Programmatically

DrillBit components can be configured programmatically instead of using a configuration file. The Drill.Extensibility.IDrillBitSetup interface is implemented by classes that are used to configure a DrillBit using custom code. A DrillBitSetup class can be thought of as a registry class used to register types in an underlying DI container, a class that finds and executes registry classes or can be any necessary custom code.

IDrillBitSetup

Please consider the Drill.Extensibility.IDrillBitSetup interface definition:

    public interface IDrillBitSetup
    {
        void Configure(IDrillBit drillBit, object state);
    }

The Configure method is called after the DrillBit object is created and its specific sequence is dependent upon the implementation of the DrillBit type. The drillBit argument is set to the reference of the DrillBit instance being configured. The state argument is specific to the implementation of the DrillBit type. It may be null but it is usually set to the reference of the underlying resolver object of the DrillBit when applicable (e.g. the underlying DI container or service locator).

DrillBitSetupBase<,>

The generic abstract base class, Drill.Extensibility.DrillBitSetupBase<TDrillBit, TResolverObject>, is a base implementation of the IDrillBitSetup interface that handles the boilerplate logic of most DrillBitSetup implementations. This class simplifies the creation of DrillBitSetup classes which can simply derive from DrillBitSetupBase<,> and override the void Configure(TResolverObject resolverObject) method.

The DrillBits that are included with Drill each provide an abstract base class that derives from the DrillBitSetupBase<,> generic abstract base class further simplifying the creation of DrillBitSetup classes for specific DrillBit components.

The included DrillBit-specific setup base classes include:
  • Drill.DrillBits.Autofac.AutofacDrillBitSetup
  • Drill.DrillBits.StructureMap.StructureMapDrillBitSetup
  • Drill.DrillBits.Unity.UnityDrillBitSetup

Wiring up a DrillBitSetup class

When a DrillBit is configured for a dependency resolver using Drill configuration, one or more config sources are usually defined for the DrillBit. To use a custom DrillBitSetup class to configure the DrillBit, the config source must set the method attribute value to DrillBitSetup and the set value attribute to the assembly-qualified type name of the class that implements the Drill.Extensibility.IDrillBitSetup interface. During the building of the DrillBit instance, the DrillBitSetup type that is specified is instantiated and its Configure method is invoked. Multiple config sources are supported for a DrillBit, including multiple config sources using the DrillBitSetup method (or other methods too). When multiple config sources are specified, they are processed in the order that they are defined.



Last edited Nov 22, 2012 at 5:09 AM by wreynolds, version 2

Comments

No comments yet.