ASP.NET MVC Interview Questions : Part-4
Q.1 What is dependency injection?
- The DI provides the objects that they needs(dependencies).
- DI is a design pattern used to implement IoC(Inversion of Control - Here control of object is transferred to the framework).
- It allows the creation of object outside the class and provides those object to class.
- Using DI we move creation and binding outside the class.
- DI pattern has 3 classes : Client class(dependent class : Depends on service class), Service class(dependency : Provide service to client) and Injector class(Injects service class object to client class).
Q.2 How can we configure data from appsettings.json?
- We can configure using two ways :
- It is available in DI container and directly access JSON properties by injecting IConfiguration in constructor of controller or class.
- We can define readonly property of type IConfiguration.
- To access multiple values or structured data from appsettings.json, this pattern is used.
- Create a class to represent structured settings, it must be replica of appsetting.json file.
Q.3 What is session variable?
- Session means time period for something.
- Session saves data in same way as dictionary object.
- TypeCasting is required because it stores value as an object.
- It is available throughout application until session ends.
- We can maintain data until the browser gets closed.
Q.4 What's the difference between ViewData and ViewBag?
Q.5 What's the difference between TempData and ViewBag?
Thank You!!!
For more understanding watch below video :
Comments
Post a Comment