Posts

Showing posts from December, 2018

Dependency Injection in C#

             Dependency Injection is a Software Design Pattern for make Loosely coupled code.There are 3 main ways to implement dependency injection.They are Constructor Injection Property Injection Method Injection 1.Constructor Injection                             It uses only one Parameterized constructor. (e.g) 1. using System; interface ICar { void ShowColor(); } class Maruthi:ICar { public void ShowColor() { Console.WriteLine("Maruthi Car"); } } class ConstructorInjection {    private Maruthi _maruthi; public ConstructorInjection(Maruthi m) { _maruthi=m; } public void ShowColor() { _maruthi.ShowColor(); } } public class Program { public static void Main() { ConstructorInjection cn = new ConstructorInjection(new Maruthi()); cn.ShowColor(); } } 2. public...

Interfaces in C#

Interfaces can have set of properties,methods,events and indexers but has no implementations. The implementation of each member of the interfaces will be created in the child classes.So we may see all these vividly below. An interface defines the signature of properties,methods,events and indexers but not an implementations. Interface members are public by default .So don't need to specify access specifiers. Access modifiers of the Interface can't be changed.Because it is Internal by default . The class must be implemented all the properties,methods,events and indexers of the interface if  the class inherits the interface. The implementation of the properties,methods,events and indexers in the class must have the access specifier public . Object can't be created for an Interface. (e.g) using System; public class Program { public static void Main() { Child child = new Child(); child.Show(); child.ShowAge(); child.ShowN...

Inheritance example program

Program using System; public class Program { public static void Main() { DisplayYear s = new DisplayYear(); s.DisplayName(); s.WishMe(); s.ShowYear(); } } class Newyear { public  virtual void DisplayName() { Console.WriteLine("Wish"); } } class Wish:Newyear { public  override void DisplayName() { base.DisplayName(); Console.WriteLine("You"); } public void WishMe() { Console.WriteLine("Happy New year"); } } class DisplayYear:Wish { public void ShowYear() { Console.WriteLine("2019"); } } Output Wish You Happy New year 2019

Know vocabularies-I

Present                  Past            Past participle Send                      sent            sent Smite                    smote        smitten Strike                    struck        struck Undergo               underwent undergone Wear                      wore         ...

ViewData,ViewBag,TempData and Session in Dotnet Core

           Today we are gonna learn about data transfer mediums in dot net core.I believe it will be helpful to make a flexible web applications.Here we go, ViewData           *It is the object of dictionary.It is derieved from ViewDataDictionary class.               public ViewDataDictionary ViewData{get;set;}         *It is used to pass data from controller to corresponding view.         *Its lifespan lies only during the current request.         *Its value will be null if redirection occurs.         *Typcasting is required to get data and null value checking has to be done to avoid error. ViewBag            *It is a property of ControllerBase class.             public object ViewBag{get;}          *It is used to pa...

Authentication in Asp.net

Authentication is the process of obtaining some sort of credentials from the users and validates the users identity based on the credentials.There are 3 main authentication types.They are 1.Windows authentication 2.Forms authentication 3.Token-based authentication 1.Windows authentication This uses local windows users and groups to authenticate.This  supports only windows operating system.So it  is suitable for Intranet networks where the servers ,clients and users all belong to the same windows domain.It's further classified in to 3 types a)Basic authentication           Username and password is sent as Base64-encoded strings.It is very week form of authentication. b) Digest authentication          It over comes the issues of basic authentication by using MD5 Hashed.This is very hard to decipher. c) Integrated authentication     Kerberos authentication or NT ...

Dynamic table binding using jQuery ajax call

Today we are gonna learn about dynamic table binding using jQuery.This is very useful in most cases.We need to create a new HTML table and bind using jQuery. So let's start here. jQuery $(document).ready(function () { var tr=''; $.ajax({ type: "post", url: "Provide your ajax function url here", dataType: "json", success: function (data) { if (data.length!= 0) { $.each(data, function (key, data) { tr+= "<tr><td>" + data.id+ "' </td></tr>"; }); } $('#test tbody').empty().append(tr); }, error: function (error) { alert(error); } }); }); HTML <table id="test"> <thead></thead> <tbody></tbody> </table>