Search code examples
asp.net-mvc-3entity-framework-4n-tier-architectureasp.net-mvc-scaffolding

Is MVC 3 Scaffolding usable in n-layer applications?


I've seen some examples of ASP.NET MVC3 Scaffolding but those are always simple basic applications. What about layered/tiered solution with several Projects:

/Data  
/Repository  
/Services  
/UI (MVC3)  

The basic scaffolding pushes everything into the controller.

Can the scaffolding template be customized so it takes POCOs from Data project, then creates repository in a Repository project, services in a Service project and finally creates a thin controller in MVC that knows nothing about the data context?

I'm little confused because it's a real productivity booster.


Solution

  • If you use the -Repository flag, you get a repository. With the default templates, that goes in the Model folder (if using areas, it goes in the corresponding Area Model folder).

    You can customise the templates that MvcScaffolding uses (see Steven Sanderson MVCConf2 video). However, to get things to go into separate projects, etc, is going to be difficult, if you have never used powershell script.

    There is of course, nothing to stop you moving the files, renaming the namespaces, etc. Yes it takes a bit of work, but it is a lot better than nothing. I do it, it takes me all of 10 minutes.

    I would expect someone will produce a NuGet package of that sort of thing soon, or else extra tooling to make it easier.

    As you say, it is a productivity booster, but maybe you still just gotta do a bit yourself.