Templates Improve Application Development INL s use of Microsoft Model-View-Controller (MVC) with custom templates has improved application development productivity May 2, 2016, Dan Sleight [insert optional photo(s) here]
Background.NET Custom Application Development Team M&O, Divestment and New Development Projects Coding Standards had aged Written during early days of Web Forms development Largely ignored as they had become irrelevant Just beginning to use MVC Developers trying to force Web Forms methods into MVC Telerik (Kendo) Struggling without Server Side Events Weak front-end skills Others trying to take big bites Some not wanting to admit they are lost
Personal Experience Hired in late March 2015 as Staff-Aug Deep MVC background First Projects Divestment of an application that was rarely used because of the poor user experience Divestment of an internal classified ad app Public facing applications that had been previously started using MVC Divestment of IP Disclosure system Beginning of every project seemed to be doing the same tasks Started getting the app to a generic stopping point and saving for the next project Started developing shared tooling
Bootstrap/Bootswatch.com Based Top Menu Uses themes from http://www.bootswatch.com Very clean, strict bootstrap markup SASS (.scss)
Left-Hand Menu Based Uses small theme (css) files Uses Bootstrap markup Adds classes to handle the breadcrumbs and titles
Under the Hood C# Using features from C# 6 Encouraging learning new features in the language, staying current LinqToSql Less overhead than EF SQL Server ELMAH Clean custom error pages in the web.config transforms HTML 5 CSS 3 (Media Queries, etc) jquery Bootstrap FontAwesome SASS (.scss) Requires Mads Kristensen s Web Compiler extension in Visual Studio 2015 Web Essentials for 2013
Project Generation from the Template The templates exist in a solution where they can be adjusted and debugged WinForms app in the solution to generate the project Generation Parameters Path Connection Strings (Acceptance, Production, etc) Root Namespace {namespace}.data {namespace}.business {namespace}.mvc Template/Color Scheme Option to generate tables, stub the current user as admin Requires little work to get running after generation
What is done already? Web.config transforms Database Connection Strings Custom Error Pages Elmah logging to Database Windows Authentication User Management Role Manager Output Caching Session State Cookie Renamed Server Headers Obfuscated Compression Mime Types Nuget Packages (must be restored) View Engines stripped down Anti Forgery Token cookie name changed, requires SSL Routes reconfigured with ignores, Helper paths mapped Menu object for managing menus and permissions Developer controller with sample code, styles guide Helpers referenced
What about the Helpers BsHelper Contains a number of helpers to help with a bootstrap based project HtmlHelpers that add bootstrap specific classes to elements HtmlHelpers that stub up front-end libraries such as DatePicker.js, DataTables.net, Chosen, etc Contains controller for returning dependent js and css files used in the HtmlHelpers SNumber Helper Facilitates access to extended User information stored in a read-only database Dependent on BsHelper Primary Html Helper for searching and selecting employees
Establishing Boundaries and Guidelines The template establishes a clear three layer system, keeping the layers in different projects: {namespace}.data {namespace}.business {namespace}.mvc We encourage THICK objects and THIN controllers Models should be used for binding from the form, not the object directly to avoid overposting vulnerabilities Objects should self-hydrate (lazy load) child objects and bind look-up objects from a single DB call when possible Database column names should directly map to the object properties Objects should have static methods for getters, binding should not happen outside of the object*
Scaf Scaf is a scaffolder based on the database tables Since our database follows naming conventions, we can use the database DDL to generate scaffolding for our objects Scaf allows us to do custom formatting to quickly stub up html forms, etc
So, what are you saying? Technical Debt is one of the biggest concerns for our team, and finding ways to reduce that technical debt helps us stay relevant We re a.net team, and MVC is our platform for new development, so establishing a common starting point beyond the default solutions is important to us Being flexible is the advantage we have over configure systems. Our templates create guidelines, but don t lock out the flexibility we need to be innovative and meet needs Developers should know: If you write it once, consider putting it in a method If you write it twice, it should be in a method If you write it three times, you should consider changing jobs Teams should find ways to apply this principle outside the scope of a single project through templating and tooling.
Contact Info Dan Sleight Idaho National Laboratory daniel.sleight@inl.gov