MVC 3 脚手架可以在 n 层应用程序中使用吗?
我见过一些 ASP.NET MVC3 脚手架的示例,但这些都是简单的基本应用程序。具有多个项目的分层/分层解决方案怎么样:
/Data
/Repository
/Services
/UI (MVC3)
基本的脚手架将所有内容推入控制器中。
是否可以自定义脚手架模板,以便它从数据项目中获取 POCO,然后在存储库项目中创建存储库,在服务项目中创建服务,最后在 MVC 中创建一个对数据上下文一无所知的瘦控制器?
我有点困惑,因为它确实是生产力的助推器。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 -Repository 标志,您将获得一个存储库。使用默认模板,该模板位于模型文件夹中(如果使用区域,则位于相应的区域模型文件夹中)。
您可以自定义 MvcScaffolding 使用的模板(请参阅 Steven Sanderson MVCConf2 视频)。但是,如果您从未使用过 powershell 脚本,那么将事物放入单独的项目等将会很困难。
当然,没有什么可以阻止您移动文件、重命名命名空间等。是的,这需要一些工作,但总比没有好得多。我做到了,花了我整整10分钟。
我希望有人很快就会制作出此类东西的 NuGet 包,或者额外的工具来使其变得更容易。
正如你所说,它可以提高生产力,但也许你仍然需要自己做一点。
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.
查看 Nuget mvcscaffolding 项目 - 不错的博客文章,位于
http://blog.stevensanderson.com/ 2011/04/08/mvcscaffolding-scaffolding-custom-collections-of-files/
您可以自定义它以了解您想要的任何层想要并且肯定可以参考其他基于存储库的项目等。
Check out the Nuget mvcscaffolding project - good blog posts at
http://blog.stevensanderson.com/2011/04/08/mvcscaffolding-scaffolding-custom-collections-of-files/
You can customize this to be aware of whatever layers you want and surely can reference other repository based projects etc.