Monday, February 27, 2017

Dependency Injection usage in practically.....

DI is the concept where in framework comes in and injects the object rather than you creating it. (loosely coupled, decoupled with unnecessary work)

It helps to create classes that are loosely coupled and separate the logic dependency.

Applying dependency injection we can achieve re-usability, maintainability and write testable code

  • a
    • b




References:

http://codes2know.com/c-dependency-injection/

B' happiiiiiii always..............!

Thursday, July 7, 2016

Optimize code using Threading


Threading is quite helpful to optimize the performance of programming  

Parallel code execution
Processor given sometimes to execute one function and then other function parallel
  • Thread.Sleep 
    • synchronous
    • when want to block the current thread 
    • this help to run as individual thread

  • Task.Delay
    • asynchronous
    • when want only to delay the current thread without blocking
    • this help to run multiple thread at once


Sample code:




  • Foreground thread
    • thread will keep on running even though the main application is quit 
  • Background thread
    •  all the thread die if the main application quit

//Reference
using System.Threading;
using System.Threading.Task;

//Create thread
Thread obj1 = new Thread(Function1);
Thread obj2 = new Thread(Function2);

//Specially for background thread 
obj1.IsBackground = true;

//Invoke thread
obj1.Start();

static void Function1()
{
//do something 
//Wait 4 seconds
Thread.Sleep(4000);

}


References:

B' happiiiiiii always..............!

Wednesday, March 23, 2016

C#6 comes with new features..


Final version of C# 6 having been released, with couple of new features


  • Static Using Syntax
static qualifiers can be use as a namespace reference





  • Auto-Property Initializers

ability property inline initialization rather that and initialized through constructor




  • Dictionary Initializers & String Interpolation

cleaner way to  initialize the Dictionary and Concatenate strings together


  • NameOf Expression

handling exception with less codes



  • Expression Bodied Function & Property

functions and properties in lambda expressions save you from defining function and property statement block


  • Exception Filters

define specific catch block rather than specify a condition for a catch block



  • Await in a Catch and Finally Block

useful in log tracking without blocking, asynchronous code inside in a catch/finally block



  • Null Conditional Operator

released from NullReferenceException errors handeling


References:

B' happiiiiiii always..............!

Tuesday, August 11, 2015

how to work with SignalR

In real-time the server is aware of the data updates, event occurrences, etc.This is commonly achieved through methods like continuous polling, but this is incur a lot of traffic and load to the server.

So as an alternative SignalR is popup. SignalR is an Asp.Net library, which is designed to use the existing transport technologies underneath based on the client nature and the support it offers. 

This is capable of pushing the data to a wide variety of clients. So because of this new trend developers no need to worry about which server push transport but to use and deciding on the fallback in case of unsupported scenarios.

SignalR uses transports that are required to do real-time work between client and server. Each and every transports have its own requirement. So if these requirements are not met, SignalR will attempt to use other transports (one at a time) to make its connections.
  • WebSocket 
  • Server Sent Events
  • Forever Frame
  • Ajax long polling



Monday, June 22, 2015

Tag Helpers replaced HTML helpers...


Tag Helpers are an alternative to HTML helpers for generating HTML. MVC6 introduces a new feature called Tag Helpers. 

Tag helpers can be used to improve the readability of your Razor views that generate HTML forms. Tag Helpers provide a cleaner syntax that more closely matches the HTML that will be generated.

Enable Tag Helpers

Tag Helpers are located in the Microsoft.AspNet.Mvc.TagHelpers package, So add a reference to that in the project.json file. Then can enable tag helpers by adding this @addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers" into _GlobalImports.cshtml.

HTML helper vs Tag helper

It might look like Tag Helpers are just a syntax change with no obvious benefits. The difference however, can make your Razor forms much more readable


As you can see, the HTML helper approach becomes very hard to understand while the tag helper approach is very clear and concise.  

Most Common Tag Helpers
  • Tag helper automatically get the value from the Display attribute
  • HTML attributes that added to the textarea element will be merged with the generated attributes.
  • All the functionality provided by the select tag helper provides a clean syntax for generating select elements based on the values in the model
  • Any HTML attributes you add to the form element will be included in the generated HTML
  • validation message tag helper directly after the input tag helper for the same property. This allows for the validation message to be displayed in close proximity to the input that it applies to

Wednesday, June 17, 2015

Why AngularJS awesome...?


AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. Angular's data binding and dependency injection eliminate much of the code.

Angular is client-side MVC framework, it extends HTML with new attributes. it's perfect for Single Page Applications (SPAs).

Basics of AngularJS: 


ng-app : defines AngularJS application

ng-init : initialize AngularJS application variables

ng-model : binds the value of HTML controls to application data
ng-bind : binds application data to the HTML view
ng-controller : defines the controller
ng-repeat : clones HTML elements once for each item in a collection

*** We can use data-ng-, instead of ng-, if you want to make your page HTML valid

ex:

Friday, April 10, 2015

K's in vNext

MVC6 is know as vNext. The goal is to create a lean and composable .NET stack for building modern cloud-based apps.

 vNext name bind up with 3 K components. 

So we will have a quick overview about K-world components 


ASP.NET vNext comes with a new runtime environment called KRE. Besides KRE that runs ASP.NET vNext applications there are also tools for managing KRE versions and NuGet packages that application uses. 

K has three components:

This is a Powershell script used to get the runtime and manage multiple versions of it being on the machine at the same time.

KRE – K Runtime Environment is the code required to bootstrap and run an ASP.NET vNext application. This includes things like the compilation system, SDK tools, and the native CLR hosts.

KVM – K Version Manager is for updating and installing different versions of KRE. KVM is also used to set default KRE version.

KPM – K Package Manager manages packages needed by applications to run. Packages in this context are NuGet package


Install KVM for the first time you have to do the following steps:
  • Open a command prompt with Run as administrator.
  • Run the following command:
    • @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.ps1'))
  • The script installs KVM for the current user.
  • Exit the command prompt window and start another as an administrator (you need to start a new command prompt to get the updated path environment).
  • Upgrade KVM with the following command:
    • KVM upgrade

References:


B' happiiiiiii always..............!