Fluent interface from Autofac IoC in DSL configuration

Fluent registration API from the Autofac inversion of control container is really addictive.

I’ve just found myself writing the code for the DSL prototype project, that has nothing to do with the IoC (yet), but has feel similar to the Autofac component registrations:

/// <summary>  Default compiler pipeline for this project  </summary>
public sealed class MyPipeline : CompileToFile
{
  public MyPipeline()
  {
    var provider = new BaseClassProviderOnRules();

    // compile all *.boo from Requests folder against BaseRequestWorkflow
    provider.Register<BaseRequestWorkflow>(“Requests”, “InitWorkflow”)
      .Importing(“Request.Core”);

    // compile all *.boo from Requests folder against BaseRequestDocumenter
    // and add “_Documenter” suffix to class names
    provider.Register<BaseRequestDocumenter>(“Requests”, “DescribeWorkflow”)
      .Naming(file => file + “_Documenter”)
      .Importing(“Request.Core”);

    provider.Register<BaseClass>(“Samples”, “InitializeMethod”);

    // customize the compiler pipeline
    Insert(1, new UseSymbolsStep());
    Insert(2, new MultiBaseClassCompilerStep(provider));
  }
}

0 Responses to “Fluent interface from Autofac IoC in DSL configuration”


  1. No Comments

Leave a Reply