API design challenge – builder

Now that Wind­sor 3 is released I can con­cen­trate on some of my other ideas and projects. While work­ing on one of them, called Car­tog­ra­pher, I encoun­tered an inter­est­ing API design problem.

 

I have a class (a builder to be pre­cise) that has a task of set­ting up a cen­tral object (an IMap­per imple­men­ta­tion) in Car­tog­ra­pher (If you’ve ever used Aut­o­fac, it is some­what anal­o­gous to Con­tainer­Builder). What is inter­est­ing about it, is I have three goals for that class:

  1. Pro­vide API for high level con­fig­u­ra­tion and exten­sion points that are uni­ver­sal to and intrin­sic to any IMap­per implementation.
  2. Pro­vide API for low level con­fig­u­ra­tion of the default IMap­per imple­men­ta­tion that the builder cre­ates, that will meet the fol­low­ing criteria:
    1. Not force user to cus­tomize any­thing, as the default setup should be enough to get started in most cases.
    2. Allow users to eas­ily swap/extend parts of the depen­dency chain of the default mapper.
    3. Work well and be nat­ural both with and with­out IoC container .
  3. Be sim­ple and dis­cov­er­able to the users (and pro­vide good Intel­lisense experience).

How would you design the API for this class?

 

Oh, and happy new year.

  • Boris Letocha

    I tried to par­tially reim­ple­ment Aut­o­fac Con­tainer Builder using Traits like sys­tem, unfor­tu­nately it has lim­i­ta­tions due to exten­sions meth­ods can­not be declared on generic class, because of that "As()" needs to be mem­ber of IReg­is­tra­tion inter­face.
    For work in progress look here: https://github.com/Bobris/BTDB/tree/unstable/BTDB/IOC
    It is really hard to really imple­ment com­pile time mix­ins to have per­fect intel­lisence with clean and exten­si­ble design.
    Happy new year …

  • http://blog.ploeh.dk Mark See­mann
  • http://twitter.com/Scooletz Scoo­letz

    Pro­vide the inter­face for high level con­fig­u­ra­tion ICon­fig­u­ra­tion, pro­vide sec­ond inter­face IDe­fault­Map­per­Con­fig­u­ra­tion imple­ment­ing the ICon­fig­u­ra­tion with addi­tional prop­erty Default­Map­per. The prop­erty would be respon­si­ble for low level con­fig­u­ra­tion.
    What I mean is to sth like Advanced prop­erty of the RavenDB session