|
|
Hello,
I've been using the scaffolding stuff for a while, but i'm wondering if there is a way to scaffold a full model. Let's say, given a DbContext call "Scaffold MyDbContext" that automatically creates the actions and the views for all the clases in
the EF model.
Thank you in advance.
|
|
May 26, 2011 at 8:09 PM
Edited May 26, 2011 at 8:09 PM
|
Sure! Read through Steve's articles #6 and #7 cafefully. He details how to scaffold multiple files as once. Create your own custom scaffolder and include the scaffold commands for other templates in your primary ps1 file. With some trail and error I was
able to write a custom scaffolder that generates a BaseController (all my controllers inherit from it -- keeps things dry), and my service and repository interfaces / classes, saves me a lot of time when creating a new MVC3 project:
Package Manager Console:
PM> Scaffold CustomScaffolder Layers
[Project]CodeTemplates/Scaffolders/Layers/Layers.ps1
[T4Scaffolding.Scaffolder(Description = "Enter a description of Layers here")][CmdletBinding()]
param(
[string]$Project,
[string]$CodeLanguage,
[string[]]$TemplateFolders,
[switch]$Force = $false
)
Write-Host "Scaffolding controller, business and data layers..."
Scaffold BaseControllerLayer -Force:$Force
Scaffold IServiceLayer -Force:$Force
Scaffold ServiceLayer -Force:$Force
Scaffold IRepositoryLayer -Force:$Force
Scaffold RepositoryLayer -Force:$Force
Write-Host "Done."
|
|
|
|
Interesting, can you give us some guidance on how you customized this please,
|
|
|
|
@srailback : can you please indicate where (which filee) to add the script you have posted ?
thank you.
|
|