Thursday 29 July 2021

Angular topics to learn

1. Angular components 
Components are the most basic UI building block of an Angular app.
An Angular app contains a tree of Angular components.
A component must belong to an NgModule in order for it to be available to another component or application
@Component({
  selector: 'app-componentname',
  templateUrl: './componentname.component.html',
  styleUrls: ['./componentname.component.css']
})

app.module.ts
it have @NgModule it holds component declaration, Import section, Providers(interceptor) & Bootstrap
Example: 
import { APP_INITIALIZER, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { AppHeaderComponent } from './components/app-header/app-header.component';
import { LoaderComponent } from './shared-module/loader/loader.component';
import { AppFooterComponent } from './components/app-footer/app-footer.component';
import { SettingService } from './core/services/setting-service/setting.service';
import { LoaderInterceptor } from './core/interceptors/loader-interceptor';

@NgModule({
  declarations: [
    AppComponent,
    AppHeaderComponent,
    LoaderComponent,
    AppFooterComponent,
    CallbackComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    BrowserAnimationsModule,
    DialogModule,
  ],
  providers: [
SettingService,
    {
      provide: APP_INITIALIZER,
      useFactory: (setting: SettingService) => function () { return setting.getJSON(); },
      deps: [SettingService],
      multi: true
    },
    {
      provide: HTTP_INTERCEPTORS,
      useClass: LoaderInterceptor,
      multi: true
    },
    {
      provide: HTTP_INTERCEPTORS,
      useClass: HttpServiceInterceptor,
      multi: true
    }
  ],
  bootstrap: [AppComponent]
})

app.component.ts
it will initialize the app component  and required inputs.
app.component.html
this is parent component for all other components.
Example:
<div *ngIf="!isAuthorized">
    <app-app-header></app-app-header>
        <main>
            <router-outlet></router-outlet>
        </main>
    <app-footer></app-footer>
</div>

There are four main types of angular decorators:
  • Class decorators, such as @Component and @NgModule
  • Property decorators for properties inside classes, such as @Input and @Output
  • Method decorators for methods inside classes, such as @HostListener
  • Parameter decorators for parameters inside class constructors, such as @Inject
2. Angular Bindings - [ngModel] also called two way binding - Property binding - Event binding 
3. Angular forms - Template driven forms - Reactive forms - FormControl - FormGroup - FormArray - FormBuilder 
4. Angular architechure - Modules - Components - Templates - Metadata - Data binding - Directives - Services - Dependency injection 
5. Lazy loading
6. Interceptor - HttpInterceptor is an interface implemented to the class - HttpRequest - HttpHandler - HttpEvent 
7. Canactivate and candeactivate 
8. Subject Behaviour, Replay, Async subject 
9. Angualr routing 
10. Dependency injections 
11. Material angular 
12. Angular Compiler - JIT - AOT 
13. Angular build files 
14. Angular Testing 
15. Angular life cycle -
 Ngonchnages() - NgonInit() - NgDoChecked() - NgAfterContentInit() - NgAfterContentChecked() - NgAfterViewInit() - NgAfterViewChecked() - NgDestroy() 



16. Rxjs 
17. Directives * Build in * Attribute * structural 
18. Custom directives 
19.Templates 
20. Services 
21. Authentication 
22. HTTP Services 
23. Animations 
24. Pipes - Completed 
25. Input and Outputs 
26. Deployment 
27. Package.json 
28. Libraries 
29. angular.json 
30. Routing guard 
31.state management

Wednesday 26 May 2021

Abstract class, method & Interface in Factory pattern method.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace EfCodeF.FactoryPatern
{
    /// <summary>
    /// Class contains input params
    /// </summary>
    public class FileDto
    {
        public string FileName { getset; }
        public string StorageContainer { getset; }
        public string FileBase64 { getset; }
        public string StorageType { getset; }

    }
    /// <summary>
    /// abstract class with common implementaion 
    /// </summary>
    public abstract class AStorage
    {
        public abstract string StorageRepository { get; }
        /// comon methods will provide implementation within base abstract class
        public virtual string GetFileExtension(string fileName)
        {
            return fileName.Substring(fileName.LastIndexOf('.'));
        }
    }
    public interface IStorage
    {
          bool SaveFile(FileDto fileDto);
          string GetFileBase64(string storageContainer,string fileName);

    }

    class Azure : AStorageIStorage
    {
        public override string StorageRepository
        {
            get { return "Azure"; }
        }
       
        public  bool SaveFile(FileDto fileDto)
        {
            /// save file in Azure
            
            return true;
        }
        public string GetFileBase64(string storageContainerstring fileName)
        {
            ///retrieve logic here
            return fileName;
        }
    }

    class Onprem : AStorage,IStorage
    {
        public override string StorageRepository
        {
            get { return "Onprem"; }
        }
        
        public bool SaveFile(FileDto fileDto)
        {
            /// save file in onprem
            return true;
        }
        public string GetFileBase64(string storageContainerstring fileName)
        {
            ///retrieve logic here
            return fileName;
        }
    }


   public abstract class StorageFactory
    {
        public abstract IStorage GetStorageInstance();
        public abstract AStorage GetStorage();
    }

    class AzureFactory : StorageFactory
    {
        public override IStorage GetStorageInstance()
        {
            return new Azure();
        }
        public override AStorage GetStorage()
        {
            return new Azure();
        }
        
    }

    class OnpremFactory : StorageFactory
    {
        public override IStorage GetStorageInstance()
        {
            return new Onprem();
        }
        public override AStorage GetStorage()
        {
            return new Onprem();
        }
        
    }

    ////controller or main class save file
    public class main
    {
        public bool SaveFile(FileDto fileDto)
        {
            StorageFactory _storageFactory = GetStorageFactory(fileDto.StorageType);
            AStorage _storage = _storageFactory.GetStorage();
            ///calling abstract class common method
            _storage.GetFileExtension("arul.txt");
            IStorage storage = _storageFactory.GetStorageInstance();

            storage.SaveFile(fileDto);
            return true;
        }
        public StorageFactory GetStorageFactory(string storageType)
        {
            StorageFactory _storageFactory = null;
             
            switch (storageType)
            {
                case "Azure":
                    _storageFactory = new AzureFactory();
                    
                    break;

                case "Onprem":
                    _storageFactory = new OnpremFactory();
                    break;
            }
            return _storageFactory;
        }
    }


}

Sunday 23 May 2021

C# Concepts to learn

1. Class

Everything in C# is associated with classes and objects, along with its attributes and methods.

2.Encapsulation

Encapsulation is implemented by using access specifiers. An access specifier defines the scope and visibility of a class member.

Public-Any public member can be accessed from outside the class.

Private- Access only within a class or scope

Protected- allows a child class to access the member variables and member functions of its base class.

Internal- allows a class to expose its member variables and member functions to other functions and objects in the current assembly.

Protected internal -allows a class to hide its member variables and member functions from other class objects and functions, except a child class within the same application.

3.Polymorphism

polymorphism means having many forms. In object-oriented programming paradigm, polymorphism is often expressed as 'one interface, multiple functions'.

Polymorphism can be static or dynamic. In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at run-time.

static polymorphism

  • Function overloading ex: void print(int x){}; void print (string x){};
  • Operator overloading

Dynamic Polymorphism

C# allows you to create abstract classes that are used to provide partial class implementation of an interface. Implementation is completed when a derived class inherits from it. Abstract classes contain abstract methods, which are implemented by the derived class. The derived classes have more specialized functionality.

Dynamic polymorphism is implemented by abstract classes and virtual functions.

Here are the rules about abstract classes −

  • You cannot create an instance of an abstract class

  • You cannot declare an abstract method outside an abstract class

  • When a class is declared sealed, it cannot be inherited, abstract classes cannot be declared sealed.

4.Inheritance 

it's an concept of base class and derived class. derived class can access base class member and member functions.

-Single inheritance( class A{}; sealed class B:A{}; 

-Multilevel inheritance ( class A{}; class B:A{}; class C:B) 

-Multiple not possible but can achieve through interface.

5.Interface

it contains function declaration only with default public access specifies, implemented/derived class should provide definition declared functions in interface.

 Public interface ICalculator

{

int sum(int x,int y);

}

public class Calc : ICalculator

{

public int sum(int x,int y){ return x+y;}

}

6.Abstraction

Data abstraction is the process of hiding certain details and showing only essential information to the user.
Abstraction can be achieved with either abstract classes or interfaces (which you will learn more about in the next chapter).

The abstract keyword is used for classes and methods:

  • Abstract class: is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class).

  • Abstract method: can only be used in an abstract class, and it does not have a body. The body is provided by the derived class (inherited from).

An abstract class can have both abstract and regular methods:

// Abstract class
abstract class Animal
{
  // Abstract method (does not have a body)
  public abstract void animalSound();
  // Regular method
  public void sleep()
  {
    Console.WriteLine("Zzz");
  }
}

// Derived class (inherit from Animal)
class Pig : Animal
{
  public override void animalSound()
  {
    // The body of animalSound() is provided here
    Console.WriteLine("The pig says: wee wee");
  }
}

class Program
{
  static void Main(string[] args)
  {
    Pig myPig = new Pig(); // Create a Pig object
    myPig.animalSound();  // Call the abstract method
    myPig.sleep();  // Call the regular method
  }
}

7.Dependancy Injection:

Dependency Injection (or inversion) is basically providing the objects that an object needs, instead of having it construct the objects themselves. It is a useful technique that makes testing easier, as it allows you to mock the dependencies.

8.Scafolding - Auto generated code for Controller CRUD operation using Entity Framework. 

9.Filters

10. Diff bw Authorize and Authentication

Authentication : need to pass login credentials, it's valid then it will return authorize response.

Authorize: after Authentication steps based on response it will validate user access to the particular action.

11.MVC architecture

12. ViewBag and ViewData and TempData

ViewData, ViewBag and TeampData for passing data from controller to view and in next request. ViewData and ViewBag are almost similar and it helps us to transfer the data from controller to view whereas TempData also works during the current and subsequent requests.

ViewData
ViewBag
TempData
It is Key-Value Dictionary collectionIt is a type objectIt is Key-Value Dictionary collection
ViewData is a dictionary object and it is property of ControllerBase classViewBag is Dynamic property of ControllerBase class.TempData is a dictionary object and it is property of controllerBase class.
ViewData is Faster than ViewBagViewBag is slower than ViewDataNA
ViewData is introduced in MVC 1.0 and available in MVC 1.0 and aboveViewBag is introduced in MVC 3.0 and available in MVC 3.0 and aboveTempData is also introduced in MVC1.0 and available in MVC 1.0 and above.
ViewData also works with .net framework 3.5 and aboveViewBag only works with .net framework 4.0 and aboveTempData also works with .net framework 3.5 and above
Type Conversion code is required while enumeratingIn depth, ViewBag is used dynamic, so there is no need to type conversion while enumerating.Type Conversion code is required while enumerating
Its value becomes null if redirection has occurred.Same as ViewDataTempData is used to pass data between two consecutive requests.
It lies only during the current request.Same as ViewDataTempData only works during the current and subsequent request

13.Seesion, Temp Data and Cookies

Session: stored in server side we can access all actions until get expired

Temp Data: stored in server side we can access all actions once read the value it will get expired.

Cookies: Stored in client side Each request & response it will pass. not secured one so not add sensitive info

14.Action Verbs

Action Verbs supported by MVC framework are HttpGet, HttpPost, HttpPut, HttpDelete, HttpOptions & HttpPatch, NonAction 

15.Areas in MVC

16.Partial View

17.Partial Class

18.Inner class

19.Linq

- Sum 

-Count

-Group by

- Min & Max

-Join

20. Quarriable & Enumerable

21. Render Action methods

22.Routing

23.Startup config

24.Constructors & types

25.Method Overload & Override

When two or more methods in the same class have the same name but different parameters, it's called Overloading. When the method signature (name and parameters) are the same in the superclass and the child class, it's called Overriding.

26.Singleton class and object

Singleton :In this pattern, a class has only one instance in the program that provides a global point of access to it. In other words, a singleton is a class that allows only a single instance of itself to be created and usually gives simple access to that instance.

The advantages of a Singleton Pattern are,

  1. Singleton pattern can implement interfaces.
  2. Can be lazy-loaded and has Static Initialization.
  3. It helps to hide dependencies.
  4. It provides a single point of access to a particular instance, so it is easy to maintain.
There are several ways to implement a Singleton Pattern in C#.
  1. No Thread Safe Singleton.
  2. Thread-Safety Singleton.
  3. Thread-Safety Singleton using Double-Check Locking.
  4. Thread-safe without a lock.
  5. Using .NET 4's Lazy<T> type.
No Thread Safety:
public sealed class SingletonA
{  
    private SingletonA() {}  
    private static SingletonA instance = null;  
    public static SingletonA Instance {  
        get {  
            if (instance == null) {  
                instance = new SingletonA();  
            }  
            return instance;  
        }  
    }  
}  
 
Thread Safety:
public sealed class SingletonA
{  
    private static readonly object lock = new object();  
    private SingletonA() {}  
    private static SingletonA instance = null;  
    public static SingletonA Instance {  
        get {
            lock(lock) {  
            if (instance == null) {  
                instance = new SingletonA();  
            }  
            return instance;  
            }
        }  
    }  
}  
 

27.Sealed class- no more inheritance

28.Dictionary & Hash table

29.Deligate and Callback

delegates detail link

C# delegates are similar to pointers to functions, in C or C++. A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime.

Delegates are especially used for implementing events and the call-back methods. All delegates are implicitly derived from the System.Delegate class.

30.Global.asax : file allows you to write code that runs in response to application-level events, such as Application_BeginRequest, application_start, application_error, session_start, session_end, etc.

31.Ioc- Inversion Of Control : It is an design principle to support Test Driven Development and Dependency Injection.

https://www.tutorialsteacher.com/ioc/introduction

IoC is a design principle which recommends the inversion of different kinds of controls in object-oriented design to achieve loose coupling between application classes. In this case, control refers to any additional responsibilities a class has, other than its main responsibility, such as control over the flow of an application, or control over the dependent object creation and binding (Remember SRP - Single Responsibility Principle). If you want to do TDD (Test Driven Development), then you must use the IoC principle, without which TDD is not possible. Learn about IoC in detail in the next chapter.

Dependency Inversion Principle

The DIP principle also helps in achieving loose coupling between classes. It is highly recommended to use DIP and IoC together in order to achieve loose coupling.DIP suggests that high-level modules should not depend on low level modules. Both should depend on abstraction.

32.Discards - C#
 C# supports discards, which are placeholder variables that are intentionally unused in application code. Discards are equivalent to unassigned variables; they don't have a value.
public static void Main() { var p = new Person("John", "Quincy", "Adams", "Boston", "MA"); // Deconstruct the person object. var (fName, _, city, _) = p; Console.WriteLine($"Hello {fName} of {city}!"); // The example displays the following output: // Hello John of Boston! }

33.Diff between Ref & Out in C#
ref keywordout keyword
It is necessary the parameters should initialize before it pass to ref.It is not necessary to initialize parameters before it pass to out.
It is not necessary to initialize the value of a parameter before returning to the calling method.It is necessary to initialize the value of a parameter before returning to the calling method.
The passing of value through ref parameter is useful when the called method also need to change the value of passed parameter.The declaring of parameter through out parameter is useful when a method return multiple values.
When ref keyword is used the data may pass in bi-directional.When out keyword is used the data only passed in unidirectional.




Sunday 16 May 2021

Access spcifiers in C#

        

protected:
The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
internal:
The type or member can be accessed by any code in the same assembly, but not from another assembly.
The "protected internal" access modifier is a union of both the "protected" and "internal" modifiers.
From MSDN, Access Modifiers (C# Programming Guide):

protected internal
:

The type or member can be accessed by any code in the assembly in which it is declared, OR from within a derived class in another assembly. Access from another assembly must take place within a class declaration that derives from the class in which the protected internal element is declared, and it must take place through an instance of the derived class type.
Note that: protected internal means "protected OR internal" (any class in the same assembly, or any derived class - even if it is in a different assembly).

private
The type or member can be accessed only by code in the same class or struct.
public
The type or member can be accessed by any other code in the same assembly or another assembly that references it.

Monday 3 May 2021

Get Table & Schema details using SQL Query

This first query will return all of the tables in the database you are querying.

 SELECT

  *

 FROM

 INFORMATION_SCHEMA.TABLES

 where table_name like '%tablename%'


The second query will return a list of all the columns and tables in the database you are querying.

SELECT
  	TABLE_NAME,
COLUMN_NAME
FROM
  	INFORMATION_SCHEMA.COLUMNS

Or, you can also query for just the COLUMNS from a specific table and return the column names from the specific table ‘Album’ in our database.

SELECT
	COLUMN_NAME
FROM
  	INFORMATION_SCHEMA.COLUMNS
WHERE
	TABLE_NAME = 'Album'