ASP.NET MVC Interview Questions Part 3

Hey Guys I hope that you are Enjoying with my Blogs Writing and in this blog we will cover Interview question of ASP.NET MVC Core. So Lets Start....
                              

     Q. What is dependency injection ?
  • Dependency injection is a practice of providing dependent object from outside rather than that the class creating using new keyword.  
  • .NET supports the dependency injection software design pattern, which is a techinque for achieving Inversion of Control between classes and their dependencies.     
    Q. How can we read configuration data from appsettings.json ?
  • To the config data from appsettings.json, We use the IConfiguration object which is Injected by MVC Core Dependency Injection Framework. 
    Q. What is the need of view Data ?
  • View data is a dictionary of objects that are stored and retrieve using strings as keys. It is used to transfer data from Controller to View.
  • Since View Data is a dictionary, it contains key-Value pairs where each key must be a string.
  • View Data only transfer data from controller to view , not vice-versa. It is valid only during the current page. 
    Q. What is the difference between viewdata and viewbag ? 

  • View Data and View Bag are used for the same purpose to transfer data from controller to view. 
  • View Data is nothing but a dictionary of objects and is accessible by strings as key.
  • View Data is the property of Controller that expose an instance of the ViewData Dictionary class.
  • ViewBag is very similar to View data.
  • View Bag is a dynamic property( Dynamic keyword which is introduced in .NET framework 4.0).
  • ViewBag is able to set and get value dynamically .



                                                              Thank You...!


No comments:

Post a Comment