Question How to make a controller class in a Console Application?

TheFuentes5551

New member
Joined
Dec 22, 2021
Messages
1
Programming Experience
Beginner
So I have a normal Console Application(.NET Frameworks) C# and now I am in a need of Controller classes. I don't have an option to add a Controller class so I tried to make a normal class that can inherit the main Controller. But I dont see any parrents controller class to inherit from.
My only alternative is to do a new program(Web Api) but my question is can I make controller classes in Console Application...

Thank you
 
A controller class only makes sense if you're implementing a design pattern that uses controllers. Basically, that means MVC, i.e. Model-View-Controller. The MVC pattern has existed for a long time and can be implemented any way you want. Microsoft provide their own MVC Framework specifically for web applications, where ASP.NET provides a lot of the infrastructure. When you add a controller to an ASP.NET MVC project, the Controller class that you inherit is part of that infrastructure. A Web API project is basically MVC without the V, i.e. the API returns data to a calling application instead of displaying its own views.

If you are creating a Console application then there is no MVC Framework so there is no infrastructure, so you need to implement everything yourself. You should first do some reading on the MVC design pattern to determine whether it actually makes sense in that context. It probably doesn't. If you decide it does then a controller will just be a regular class, because there is no infrastructure class to inherit.
 
I've heard some people as say that they have had success using the MVP (Model-View-Presenter) pattern for console apps. So something else to consider if the MVC pattern doesn't quite fit in for your needs.
 

Latest posts

Back
Top Bottom