Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Should I use DbContext in controller or rather use it in model or service called from coltroller? MVC ASP.NET CORE

I need to check if some data from the input form is contained in DbContext. Should I check it in controller or controller should just call method from model or service to which will do it?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Your code would be cleaner if there be a mediator called "Services". a class whose duty is to collect data from your DB and provide that to your application layer which in your case is your controller, notice just that has accessibility to your context. Also, you can take a look at here and here
to have the cleanest code

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading