Sivaji Tata

Sivaji Tata

  • NA
  • 159
  • 5.4k

Dependency injection is not working

Mar 8 2021 8:13 AM
Hi, I tried to access the services in the home controller but somehow it's not working 
 
Startup.cs
  1. public void ConfigureServices(IServiceCollection services){    
  2.     /*boilerplate's default bindings*/    
  3.     services.AddTransient<IDummy, Dummy>(p => new Dummy()    
  4.         {    
  5.             name = "from injection"    
  6.         });    
  7. }  
HomeController.cs 
  1. public IActionResult Index(IDummy dummy){  
  2.     var test = dummy.name;  
  3.     return this.View(HomeControllerAction.Index);  
  4. }

Answers (1)