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?
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.
- 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:
- Download the source and open the solution (trunk\src\Flit\Flit.sln).
- Compile it (Flit depends on Irony and NUnit, we've bundled DLLs for both of these).
- 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.
- 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!
Flit is released under the MIT License
. Use it however you like!
Please head on over to the discussions page
to give us your opinions, thoughts, and ideas.
Flit would not have come about without the usefulness of Dot
, or the helpfulness and brilliance of Roman over on the Irony