类库中的控制器和视图 [英] Controllers and Views inside a Class Library
问题描述
我有一组在许多项目中使用的控制器和视图.我想知道是否可以将其放在类库中,然后将其作为普通的lib文件重用. 我该怎么办?
I've a group of controllers and Views that I use in many projects. I was wondering if I could place then inside a class library and reuse it as a normal lib file. How can I do this?
推荐答案
绝对可行.您需要做的事情:
Definitely doable. Things you'll need:
- 通过某种方式在应用启动时注册路线.
- 一个了解引擎视图和您的应用程序特定视图的视图引擎.
第一个很简单.只需在您的库中编写一个在库中注册所有控制器的函数即可.
The first is easy. Just write a function in your library that registers all the controllers in the library.
第二个更为复杂,但是您可以阅读一些有关编写自己的视图引擎的好文章,此处.区域的概念对于将库控制器与应用程序控制器分开也是很有用的.
The second is more complicated, but you can read some good articles on writing your own view engine, here and here. The concept of Areas may be useful too for separating your library controllers from your app controllers.
此外,这个问题解决了在任意文件夹中查找视图的最简单情况.
Also, this question addresses the simplest case of finding views in an arbitrary folder.
这篇关于类库中的控制器和视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!