I just downloaded music store (microsoft sample projct) source code that based on ASP.NET 5. I don't understand there why developers from Microsoft use IActionResult interface as a return type in controllers.
What is a reason of IActionResult interface usage? Why don't just use ActionResult type.
See this post about IActionResult
vs. ActionResult
: http://forums.asp.net/post/5980446.aspx
IActionResult
allows a wider range of return types, including any custom code that implements the IActionResult
interface. ActionResult
is limited only to those classes which extend the ActionResult
abstract class (which you could also do with custom code, but using an interface allows for something like multiple inheritance, while extending a class does not).
Using interfaces as parameters will allow you to use dependency injection to obtain its dependencies and those dependencies can be replaced with mock implementations when testing which implement those interfaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With