In the last post I talked a bit about how “Convention over Configuration” is applied to container registration in the StoryTeller trunk. Another neat convention which can be found in the bootstrapping process of StoryTeller is a convention around startable instances .
Each instance in the StoryTeller assemblies whose contract applies to
StructureMaps default convention and also contains the
interface is automatically resolved and started during bootstrapping.
For example: If you’ve defined an
1 2 3 4 5 6
and an implementation for it
1 2 3 4 5
the convention will automatically resolve that implementation and call
Start() method on it. All of this is done by this little piece of
1 2 3 4
The code itself is not that hard to understand. A bit LINQ combined with
two extension methods. The first one
IsStartable() finds all known
known contracts (the plugin type) in the dependency graph who are
assignable to the
IStartable type, while the second one (
simply resolves any found contract type with the help of the container.
Short, simple and easy to remember ==> Love it