employer cover photo
employer logo

Frage im Vorstellungsgespräch bei VMware

Write a code to implement dependency injection in C#.

Antwort im Vorstellungsgespräch

Anonym

1. Dez. 2017

You can just write a constructor in ASP.MVC controller like this: private IEmployeesRepository _employeesRepository; public EmployeesController(IEmployeesRepository employeesRepository) { _employeesRepository = employeesRepository; } When using any IoC container to map IEmployeesRepository to EmployeesRepository, this constructor will get an EmployeesRepository object during initialization, which will be done through constructor injection. We can then use _employeesRepository in the controller actions.