1. Using Visual Studio 2019 with code
automation to auto-generate customized
service layers in a Contract-Driven
Architecture
John Hannah MCP
VP of Delivery
LifeCycle Delivery Services, Inc
2. Agenda
• Introduction
• What we did, and why
• Reasons to build Automation: Legacy Code Issues
• Reasons to build Automation: Greenfield Issues
• A bit about Service Layer Design
• A bit about how CodeFactory works
• Demo
• Question and Answers
3. What we did, and why
• Frequent skillset gaps on the teams we were provided
with to deliver a given project scope.
• No other automation utilities on the market did enough of
what we needed
• ReSharper, Visual Studio Templating, etc. are all options –
but do not lend themselves to refactor/reuse scenarios
• Did not want a runtime addition to our code base
• No reflection!!!
4. Reasons to build automation: Legacy Code
Issues
• There are generally a wide range of problems found in a code base
that has been inherited, most of them can be traced back to a
project timeline constraint.
• Requirements not well documented causing ‘on-the-fly’
refactoring which destroys the original design intent.
• Not having a design/architecture planned out
• New technology base has deprecated functionality (tied to
Windows 7 OS for example..)
• Skill set of original ‘designers’ or developers was… not ideal…
for the tasks at hand
• Business enforced unrealistic demands on IT resulting in a ‘just
get it done..’ mentality
• Single point of failure (ie. The ‘beer truck problem’)
• There are more..
5. Reasons to build automation: Greenfield
Issues
• This category of issues usually boil down to scope which, if not
handled by Project Management, causes a ‘space-time-continuum’
problem…
• Target every platform ever, that their 13-year old nephew likes..
• Just add this ‘one little thing..’
• Long running project that outlives a technology platform - thus
building technical debt before ever launching to production
• Failure of the Enterprise to properly articulate a roadmap that
your solution must live in…
• Inability of the Technical Lead to say ‘no’ in a way that doesn’t
get them fired..
• Changing the Architect/Architecture mid-way through a
development effort
• There are more..
6. A bit about Service Layer Design…
There are nearly as many different service layer designs as there are active teams making use of them in their
work. Building a pattern can be impacted by Micro Service Design, n-Tier Architecture, CQRS implementations,
platform constraints, etc etc.
For today we will be working through a demo with the following basic design outline.
Service.Logic.Abstraction
Data.SQL/NoSQL
Service Endpoint
(could be public,
doesn t have to be)
Global.Data
(your entitiy
definitions)
Service.Logic
7. A bit about how CodeFactory works..
CodeFactory was internally developed by our team over the last 8 years. It has gotten to the point that we are
looking to potentially turn it into a full-fledged product.
What is it?
• CodeFactory is a Visual Studio extension that allows for design-time code automation. This means no
additional libraries or code needed to have an automation framework active.
How Does it work?
• CodeFactory allows for two basic operations; Authoring and a Runtime.
• Authoring allows you to build a series of commands that natively work with Visual Studio. This authoring is
done against your own codebase via an object model (currently C# and plain old .NET)
• The runtime allows any team member with a copy of Visual Studio that has CodeFactory installed can run your
Authored template. Just drop the CodeFactory template file (*.cfx) into the root of the solution that you want
to have automation enabled on. That’s it. The Runtime takes care of the rest.
8. How does CodeFactory get customized
actions to your solution?
Create Custom
Action
Build CodeFactory
CFX
Include CFX in the
root of your target
solution
Every CF-enabled
VS will now have
the Custom actions
enabled
9. A bit about how CodeFactory works (con’t)..
What does it do?
• The CodeFactory runtime loads your automation template into Visual Studio and makes it available to the
developer(s) via the Solution Explorer (we are working on more options).
• The developer can then pick from any of the automation commands that have been defined to do their job(s).
Output?
• Output can be handled many different ways, but our out of the box tool is a combination of the CodeFactory
Code Model and T4.