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.
The controllers can just go into a class library - not much to do there. The views are a bit more difficult. You should be able to embed them in the assembly and implement a VirtualPathProvider to provide access to them.
I haven't tried this, so YMMV.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With