Welcome to the Fluent Interface Toolkit

The official project description:

FLIT (the FLuent Interface Toolkit) streamlines the design and implementation of fluent interfaces in C#. FLIT generates customisable fluent interface code from a simple text-based DSL. FLIT includes a parser, an object model, and a set of starter templates.

Okay, but what does Flit do? How can it help me?

FlitFlow.png

Flit generates classes and methods for your Fluent Interface from a simple model of states (classes) and transitions (methods). This model is a Dot-like text-based DSL, describing states, transitions, and data in a simple, DRY format.

Flit parses this DSL and builds an object model from your syntax tree. This object model is provided to a T4 template, and is used to transform your source file into a set of partial classes and methods. There are hooks (partial method declarations and an optional Visitor Pattern implementation) that allow you to act on calls to your newly-generated Fluent Interface.

Learn more about how Flit works (and see an actual example of code generated by Flit) at Flit in depth.

Why bother with that?

Sure, you could write your fluent interface the "normal" way just by hand-coding it yourself. Flit is an example of model-driven development: you can describe the software system you're trying to build (in this case, a fluent interface), and the Flit framework will transform your abstract model into a concrete implementation. The advantages of this are:
  • The model you define your fluent interface with has no repetition (which makes it easy to update your model as your software system needs to evolve).
  • The model is very succinct, you don't have to type a lot of characters to define the whole thing.
  • The templates that transform the model into concrete code are completely customisable.
    • You could decide to regenerate the code in another language, such as javascript or VBA.
    • At any point in your project you can change how you'd like your fluent interface to look (change the code style, add a new interface implementation, overload all your methods).
  • You can generate other things straight from your model source files, such as diagrams (that's why we piggybacked off the syntax of Dot).

Let me try!

The best way to build your own Fluent Interface with Flit is to try out one of the samples, then modify one of those to suit your needs. You can get the full details on how to do this at Running the Samples, or if you think you're hot, you can follow this quick list:
  1. Download the source and open the solution (trunk\src\Flit\Flit.sln).
  2. Compile it (Flit depends on Irony and NUnit, we've bundled DLLs for both of these).
  3. Open up the project settings for Flit.Samples and add a reference path to the bin folder of the Flit project. This is important because the T4 templates within the Flit.Samples project need to be able to reference the dlls you've just compiled.
  4. Press the Transform all Templates button in your solution explorer, or go and open up the tt files and re-run them by saving them.

This should have successfully regenerated the three fluent interface sample files. If anything went wrong, you can get more details here. If that all worked, why not modify a source file and see what changes you can effect. Note that T4 can't tell when you've modified a model file, you'll have to elect to rerun the templates (see point #4 above).

If that all went well, it's time to Build your own Fluent Interface. Good luck!

License

Flit is released under the MIT License. Use it however you like!

Feedback

Please head on over to the discussions page to give us your opinions, thoughts, and ideas.

Acknowledgements

Flit would not have come about without the usefulness of Dot, or the helpfulness and brilliance of Roman over on the Irony project.

Last edited Oct 18, 2009 at 8:34 PM by robfe, version 14