hung-doan / .bookmarks

My life bookmarker
0 stars 0 forks source link

use [FromService] to inject services in Controller's actions instead of constructor #49

Open hung-doan opened 6 years ago

hung-doan commented 6 years ago

https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/dependency-injection?view=aspnetcore-2.1#action-injection-with-fromservices

public IActionResult About([FromServices] IDateTime dateTime)
{
    ViewData["Message"] = "Currently on the server the time is " + dateTime.Now;

    return View();
}