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.




Friday, November 8, 2019

What is An Auxiliary Route?


A component has one primary route and zero or more auxiliary routes.. Auxiliary routes allow you to use and navigate multiple routes. To define an auxiliary route you need a named router outlet where the component of the auxiliary route will be rendered.

The name that we're giving to the second outlet suggests that the outlet will be used as a sidebar for the app.

--------

Each component has one primary route and zero or more auxiliary outlets. Auxiliary outlets must have unique name within a component.

To define the auxiliary route we must first add a named router outlet where contents for the auxiliary route are to be rendered.

Here's an example:

import {Component} from '@angular/core';
@Component({
selector: 'app',
template: `
<nav>
<a [routerLink]="['/component-one']">Component One</a>
<a [routerLink]="['/component-two']">Component Two</a>
<a [routerLink]="[{ outlets: { 'sidebar': ['component-aux'] } }]">Component Aux</a>
</nav>
<div style="color: green; margin-top: 1rem;">Outlet:</div>
<div style="border: 2px solid green; padding: 1rem;">
<router-outlet></router-outlet>
</div>
<div style="color: green; margin-top: 1rem;">Sidebar Outlet:</div>
<div style="border: 2px solid blue; padding: 1rem;">
<router-outlet name="sidebar"></router-outlet>
</div>
`
})
export class AppComponent {
}

Next we must define the link to the auxiliary route for the application to navigate and render the contents.

<a [routerLink]="[{ outlets: { 'sidebar': ['component-aux'] } }]">
Component Aux
</a>

View Example

Each auxiliary route is an independent route which can have:

  • its own child routes

  • its own auxiliary routes

  • its own route-params

  • its own history stack


https://www.techiediaries.com/angular-router-multiple-outlets/

Followers

Link