+ All Categories
Home > Technology > MVC Scaffolding Made Easy

MVC Scaffolding Made Easy

Date post: 02-Nov-2014
Category:
Upload: mark-radacz
View: 4,757 times
Download: 2 times
Share this document with a friend
Description:
- Intro to MVC Scaffolding, CodeFirst, Repository Pattern - Customizing view and Controller Templates - Using T4 Scafoldering Commandlets - Packaging Custom Scaffolder - Customizing Scaffolding Environment Scaffolding is a way to quickly create an application layout based on data. This means there are less routine tasks that developers need to do, for example, creating your own controllers/views, CRUD methods, and validation, and more time spent on solving business problems. Learn how to customize the scaffolding using T4 templates, so that the generated output suits the needs of your application, in case you need to regenerate the scaffolding occasionally during development.
Popular Tags:
25
MvcScaffoldi ng made easy Mark J Radacz, MCTS Developer, DiscoverTec, llc http:// geekswithblogs.net/mrad [email protected]
Transcript
Page 1: MVC Scaffolding Made Easy

MvcScaffolding made easy Mark J Radacz, MCTSDeveloper, DiscoverTec, llc

http://geekswithblogs.net/mrad

[email protected]

Page 2: MVC Scaffolding Made Easy

Live the life you Love.. Love the life you live…

Page 3: MVC Scaffolding Made Easy

Who am I?

Mark J Radacz

#HusbandFatherLife-LongMateGeek Enjoying every trip around the Sun MCITP, Developer at DiscoverTec 20 years of development 10 years in .NET

Page 4: MVC Scaffolding Made Easy

Agenda Intro to MVC Scaffolding, CodeFirst,

Repository Pattern Customizing View and Controller

Templates Using T4 Scafoldering Commandlets Packaging Custom Scaffolder Customizing Scaffolding Environment

Page 5: MVC Scaffolding Made Easy

Intro to MVC Scaffolding

Page 6: MVC Scaffolding Made Easy

What is MVC Scaffolding? NuGet package that adds PowerShell

scaffolding commands to PM> Package Management Console

Productivity Enhancer Enables customization of scaffolding

execution

Page 7: MVC Scaffolding Made Easy

The Purpose of MVC Scaffolding is to……generate “starter” code…

…provide a extensibility mechanism to customize generated code…

…generate more than just MVC Controllers and Views…

Page 8: MVC Scaffolding Made Easy

MVC Scaffolding Workflow

1. Add MvcScaffolding NuGet packageInstall-Package MvcScaffolding

2. Add Model class3. Scaffold Controller and Views based on

ModelScaffold Controller Product

4. Customize generated code

Page 9: MVC Scaffolding Made Easy

Basic Scaffolding Workflow

DEMO

Page 10: MVC Scaffolding Made Easy

Customizing View and Controller Templates

Page 11: MVC Scaffolding Made Easy

Command Line Switches for Controller

Switch

• Repository• Force• ForceMode• ReferenceScritLibraries• NoChildItems

Option string

• Controller Name• ModelType• DbContextType• Project• Layout• CodeLanguage• Area• ViewScaffolder• Layout• PrimarySectionNames• TemplateFolders

Page 12: MVC Scaffolding Made Easy

Understanding Tab Expansion

Invoke-Scaffolder

“Scaffold” Alias

scaffoldingTabExpansion (context command line switch)

Page 13: MVC Scaffolding Made Easy

Command Line Switches

DEMO

Page 14: MVC Scaffolding Made Easy

Get-Scaffolder

Page 15: MVC Scaffolding Made Easy

Get-DefaultScaffolder

Page 16: MVC Scaffolding Made Easy

Standard Scaffolders with Defaults • MvcScaffolding.ActionAction

• MvcScaffolding.ControllerController

• T4Scaffolding.CustomScaffolderCustomScaffold

• T4Scaffolding.CustomTemplateCustomTemplate

• T4Scaffolding.EFDbContextDbContext

• T4Scaffolding.EFRepositoryRepository

• MvcScaffolding.ActionUnitTestUnitTest

• MvcScaffolding.RazorViewView

• MvcScaffolding.ViewsViews

Page 17: MVC Scaffolding Made Easy

Non-Default Scaffolders MvcScaffolding.ActionWithUnitTest MvcScaffolding.AspxView MvcScaffolding.ControllerWithReposi

toryGet-DefaultScaffolder Controller

Set-DefaultScaffolder Controller MvcScaffolding.ControllerWithRepository

Page 18: MVC Scaffolding Made Easy

Scaffolding Actions and Unit TestsAction:Scaffold Action -Controller TasksController -Action Foo -ViewModel Task

Unit Test:Scaffold UnitTest -Controller TasksController -Action Create

Both in 1 shot:Scaffold MvcScaffolding.ActionWithUnitTest -Controller TasksController -Action ArchiveTask -ViewModel Task

Page 19: MVC Scaffolding Made Easy

Customizing Scaffold Templates Customize the T4 template with simple

command Template added locally to solution Subsequent scaffolding commands will use

local templateScaffold CustomTemplate <ScaffolderName> <TemplateName>

Scaffold CustomTemplate View Index

Page 20: MVC Scaffolding Made Easy

Customizing View and Controller Template

DEMO

Page 21: MVC Scaffolding Made Easy

T4Scaffolding PowerShell Commandlets

Add-ClassMemberAdd-

ClassMemberViaTemplate

Add-ProjectItemViaTemplate

Find-ScaffolderTemplate Get-DefaultScaffolder

Get-PluralizedWord Get-PrimaryKeyGet-

ProjectAspNetMvcVersion

Get-ProjectFolder Get-ProjectItem

Get-ProjectLanguage Get-ProjectType Get-RelatedEntities Get-Scaffolder Get-SingularizedWord

Invoke-Scaffolder Invoke-ScaffoldTemplate Set-DefaultScaffolder Set-IsCheckedOut

Page 22: MVC Scaffolding Made Easy

Custom Scaffolders

DEMO

Page 23: MVC Scaffolding Made Easy

Summary

Whether n00b(ie) or Expert: Scaffolding should be a tool in

your toolbox!

Page 24: MVC Scaffolding Made Easy

References

Page 25: MVC Scaffolding Made Easy

Steve Sanderson on MvcScaffolding (Part 1 of 7)− http

://blog.stevensanderson.com/2011/01/13/scaffold-your-aspnet-mvc-3-project-with-the-mvcscaffolding-package/

MvcScaffolding on CodePlex− http://mvcscaffolding.codeplex.com/

Web API Scaffolding on CodePlex− http://webapiscaffolding.codeplex.com/

Steve Michelotti Blog− http://geekswithblogs.net/michelotti

References


Recommended