Last post Jun 29, 2016 11:34 AM by Anitha karishetty
Jun 16, 2016 06:06 PM|ardmore|LINK
I saw something somewhere like
public Data Data
I can't find the definition of it.
Jun 16, 2016 07:13 PM|vinz|LINK
The [FromServices] is an attribute used for DI. It tells MVC to bind a dependency on a property or method. Currently, it limits to work with action arguments only.
Jun 29, 2016 11:34 AM|Anitha karishetty|LINK
By using [FromServices] attribute u can use the service on a particular Action method , usually if u wants to use a service on every Action method in controller u can use constructor dependency concept but if you wants to use the service
on a particular Action ,it will be achieved by using this attribute. In some scenarios we dn't require calling services in every method.
public class HomeController : Controller
public IActionResult Index([FromServices] ITestInferace _objTest)
string Name = _objTest.Display();
ViewBag.Name = Name;
create interface and class
public interface ITestInferace
public class TestClass : ITestInferace
public string Display()
Register the service in startup.cs class:
public void ConfigureServices(IServiceCollection services)
// Add framework services.
Result: index.cshtml page: