Constructor with parameter in Controller - MVC

后端 未结 4 867
温柔的废话
温柔的废话 2021-02-03 14:21

I have read few articles on IOC and Unity and got my self confused :(

So going back to basics can some one tel me what the below code does?

private IStud         


        
4条回答
  •  一生所求
    2021-02-03 14:23

    In general it is called injecting the dependencies of a class , think about a class or to be precise a GOD class which handles all the stuff like ( Validating user input , coordinating with Database , generating HTML output etc) so you keep all your code in single place or you can say you develop all of your software using single class , isn't that good?

    Answer depends upon the way you organize the things , do you think , organizing things where it belongs is beneficial than you will see the problem in the above GOD class.

    So in terms of OOPS , A single class shd have a single reason to be changed but it is required to get the work done than it shd take help from the services.

    And your HomeController is doing the same thing since it does not want to be overworked , it has asked Student object to handle student.

提交回复
热议问题