Date post: | 02-Nov-2014 |
Category: |
Technology |
Upload: | mark-radacz |
View: | 4,757 times |
Download: | 2 times |
MvcScaffolding made easy Mark J Radacz, MCTSDeveloper, DiscoverTec, llc
http://geekswithblogs.net/mrad
Live the life you Love.. Love the life you live…
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
Agenda Intro to MVC Scaffolding, CodeFirst,
Repository Pattern Customizing View and Controller
Templates Using T4 Scafoldering Commandlets Packaging Custom Scaffolder Customizing Scaffolding Environment
Intro to MVC Scaffolding
What is MVC Scaffolding? NuGet package that adds PowerShell
scaffolding commands to PM> Package Management Console
Productivity Enhancer Enables customization of scaffolding
execution
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…
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
Basic Scaffolding Workflow
DEMO
Customizing View and Controller Templates
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
Understanding Tab Expansion
Invoke-Scaffolder
“Scaffold” Alias
scaffoldingTabExpansion (context command line switch)
Command Line Switches
DEMO
Get-Scaffolder
Get-DefaultScaffolder
Standard Scaffolders with Defaults • MvcScaffolding.ActionAction
• MvcScaffolding.ControllerController
• T4Scaffolding.CustomScaffolderCustomScaffold
• T4Scaffolding.CustomTemplateCustomTemplate
• T4Scaffolding.EFDbContextDbContext
• T4Scaffolding.EFRepositoryRepository
• MvcScaffolding.ActionUnitTestUnitTest
• MvcScaffolding.RazorViewView
• MvcScaffolding.ViewsViews
Non-Default Scaffolders MvcScaffolding.ActionWithUnitTest MvcScaffolding.AspxView MvcScaffolding.ControllerWithReposi
toryGet-DefaultScaffolder Controller
Set-DefaultScaffolder Controller MvcScaffolding.ControllerWithRepository
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
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
Customizing View and Controller Template
DEMO
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
Custom Scaffolders
DEMO
Summary
Whether n00b(ie) or Expert: Scaffolding should be a tool in
your toolbox!
References
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