API design challenge – builder

Now that Windsor 3 is released I can concentrate on some of my other ideas and projects. While working on one of them, called Cartographer, I encountered an interesting API design problem.


I have a class (a builder to be precise) that has a task of setting up a central object (an IMapper implementation) in Cartographer (If you’ve ever used Autofac, it is somewhat analogous to ContainerBuilder). What is interesting about it, is I have three goals for that class:

  1. Provide API for high level configuration and extension points that are universal to and intrinsic to any IMapper implementation.
  2. Provide API for low level configuration of the default IMapper implementation that the builder creates, that will meet the following criteria:
    1. Not force user to customize anything, as the default setup should be enough to get started in most cases.
    2. Allow users to easily swap/extend parts of the dependency chain of the default mapper.
    3. Work well and be natural both with and without IoC container .
  3. Be simple and discoverable to the users (and provide good Intellisense experience).

How would you design the API for this class?


Oh, and happy new year.


Boris Letocha says:

I tried to partially reimplement Autofac Container Builder using Traits like system, unfortunately it has limitations due to extensions methods cannot be declared on generic class, because of that “As()” needs to be member of IRegistration interface.
For work in progress look here: https://github.com/Bobris/BTDB/tree/unstable/BTDB/IOC
It is really hard to really implement compile time mixins to have perfect intellisence with clean and extensible design.
Happy new year …

Scooletz says:

Provide the interface for high level configuration IConfiguration, provide second interface IDefaultMapperConfiguration implementing the IConfiguration with additional property DefaultMapper. The property would be responsible for low level configuration.
What I mean is to sth like Advanced property of the RavenDB session