MVC dependency injections vs sql queries
From a c# industry standpoint, when would it be preferable to retrieve data via dependency injections and when would it be preferable to retrieve data via sql queries?
9 Replies
Dependency Injection has nothing that related to SQL Queries
???
Yes it does, you can perform a DI to retrieve an object and place it into a controller, then use it alongside a DB class which has its own methods
The alternative is to open a new sqlconnection to the db and use MVC's @sql query syntax to query
You said use DI to get DB Class to get data from database ==> Your DB Class will deal with database and retrieve data ==> not your DI
maybe u mean use DBContext vs legacy ADO.NET to retrieve data from database ?
Doesnt the DB class just contain static methods? DI is needed to ensure loose coupling between the controller and the DB class, no?
what do you mean by " DB class just contain static method" ?
The actual db object will be deal with in the controller
are you using EF Core?
No, ADO and ASP
Can you elaborate more using code? I'm confused