- 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.
“…it doesn’t generate code that suits my project.”“…the code is not complete enough for Production use.”“…I have a non-MVC project
First demo – default MvcScaffolding using diloguesDescribe filesAdd view WorkOrderAdd controler, new data contextDefault dB is SQL express – go lighter using SQL CEPM> Install-Package EntityFramework.SqlServerCompactPM> Install-Package MvcScaffoldingPM> Scaffold Controller –ModelTypeWorkOrder –ControllernameWorkOrderController – DbContextTypeWorkOrderDbcontextMVC controllers best practiceencapsulate something in the interface leverage dependency injection (to make the controllers testable)Let’s add repository PM> Scaffold Controller –ModelTypeWorkOrder –ControllernameWorkOrderController – DbContextTypeWorkOrder – RepositoryPM> Scaffold Controller –ModelTypeWorkOrder –ControllernameWorkOrderController – DbContextTypeWorkOrder – Repository -Force
Everything revolves arround command lineImportant to not only understand but also to know what’s availableSwitch = booleans – false by default, it’s pressence implies setting to true (basic Power Shell functionality)Options
Get-ModuleGet-Command –Module T4ScaffoldingGet-Alias ScaffoldGet-Help Invoke –Scaffolder (abreviated list, just the basic command options, use TAB to see all the options)Scaffold [tab]Controller –[tab]Scaffold [tab]View –[tab]
Customizing templates
ScaffoldMvcScaffolding.ActionWithUnitTest –Controller WorkOrderController –Action ArchiveWorkOrder –ViewModelWorkOrderCustomizingScaffold CustomTemplateViewIndexShow the CodeTemlate folder with T4 fileFind ModelProperty and add “DisplayName”Add new method GetDisplayName()PM> Scaffold Controller –ModelTypeWorkOrder –ControllernameWorkOrderController – DbContextTypeWorkOrder – Repository -Force