Saturday, November 30, 2019

Interview

1. What is Cross Apply in SQL Server?
2. How to test Singleton class?

[TestMethod()]
public void ReturnConnTest()
{
    SClass target = new SClass(); 
    string expected = "This is MOQ class"; 
    string actual;
    Mock<SClass> moqClass = new Mock<SClass>();
    moqClass.Setup(mc => mc.ReturnConn()).Returns(expected);
    target = moqClass.Object;
    actual = target.ReturnConn();
    Assert.AreEqual(expected, actual);
}
3. Difference between Dependency Injection and Inversion of control.

Here is an informal definition of IoC: “IoC is when you have someone else create objects for you.” So instead of writing “new MyObject” in your code, the object is created by someone else. This ‘someone else’ is normally referred to as an IoC container.

This simple explanation illustrates some very important ideas:

  1. It is called IoC because control of the object is inverted. It is not the programmer, but someone else who controls the object.
  2. IoC is relative in the sense that it only applies to some objects of the application. So there may be IoC for some objects, whereas others are under the direct control of the programmer.
DI is one of the subtypes of the IOC principle  

We can achieve Inversion of Control through various mechanisms such as: Strategy design pattern, Service Locator pattern, Factory pattern, and Dependency Injection (DI).

Inversion of Control(IoC) is a principle by which the control of objects is transferred to a container or framework. Dependency injection is a pattern through which IoC is implemented and the act of connecting objects with other objects or injecting objects into objects is done by container rather than by the object themselves.




No comments:

Followers

Link