Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Kudos for the method parameter validation, you've given me a new idea for our fluent APIs. I've hated our precondition checks anyways...</p> <p>I've built a extensibility system for a new product in development, where you can fluently describe the commands available, the user interface elements and more. This runs on top of StructureMap and FluentNHibernate, which are nice APIs too.</p> <pre><code>MenuBarController mb; // ... mb.Add(Resources.FileMenu, x =&gt; { x.Executes(CommandNames.File); x.Menu .AddButton(Resources.FileNewCommandImage, Resources.FileNew, Resources.FileNewTip, y =&gt; y.Executes(CommandNames.FileNew)) .AddButton(null, Resources.FileOpen, Resources.FileOpenTip, y =&gt; { y.Executes(CommandNames.FileOpen); y.Menu .AddButton(Resources.FileOpenFileCommandImage, Resources.OpenFromFile, Resources.OpenFromFileTop, z =&gt; z.Executes(CommandNames.FileOpenFile)) .AddButton(Resources.FileOpenRecordCommandImage, Resources.OpenRecord, Resources.OpenRecordTip, z =&gt; z.Executes(CommandNames.FileOpenRecord)); }) .AddSeperator() .AddButton(null, Resources.FileClose, Resources.FileCloseTip, y =&gt; y.Executes(CommandNames.FileClose)) .AddSeperator(); // ... }); </code></pre> <p>And you can configure all commands available like this:</p> <pre><code>Command(CommandNames.File) .Is&lt;DummyCommand&gt;() .AlwaysEnabled(); Command(CommandNames.FileNew) .Bind(Shortcut.CtrlN) .Is&lt;FileNewCommand&gt;() .Enable(WorkspaceStatusProviderNames.DocumentFactoryRegistered); Command(CommandNames.FileSave) .Bind(Shortcut.CtrlS) .Enable(WorkspaceStatusProviderNames.DocumentOpen) .Is&lt;FileSaveCommand&gt;(); Command(CommandNames.FileSaveAs) .Bind(Shortcut.CtrlShiftS) .Enable(WorkspaceStatusProviderNames.DocumentOpen) .Is&lt;FileSaveAsCommand&gt;(); Command(CommandNames.FileOpen) .Is&lt;FileOpenCommand&gt;() .Enable(WorkspaceStatusProviderNames.DocumentFactoryRegistered); Command(CommandNames.FileOpenFile) .Bind(Shortcut.CtrlO) .Is&lt;FileOpenFileCommand&gt;() .Enable(WorkspaceStatusProviderNames.DocumentFactoryRegistered); Command(CommandNames.FileOpenRecord) .Bind(Shortcut.CtrlShiftO) .Is&lt;FileOpenRecordCommand&gt;() .Enable(WorkspaceStatusProviderNames.DocumentFactoryRegistered); </code></pre> <p>Our view configure their controls for the standard edit menu commands using a service given to them by the workspace, where they just tell it to observe them:</p> <pre><code>Workspace .Observe(control1) .Observe(control2) </code></pre> <p>If the user tabs to the controls, the workspace automatically gets an appropriate adapter for the control and provides undo/redo and clipboard operations.</p> <p>It has helped us reduce the setup code dramatically and make it even more readable.</p> <hr> <p>I forgot to tell about a library we're using in our WinForms MVP model presenters to validate the views: <a href="http://www.codeplex.com/FluentValidation" rel="noreferrer">FluentValidation</a>. Really easy, really testable, really nice!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload