tag:blogger.com,1999:blog-55658186219356386432024-03-26T00:33:39.315-07:00Talk in computer language.Let's talk in computer language. Because my friend and family don't understand it.testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.comBlogger333125tag:blogger.com,1999:blog-5565818621935638643.post-55750917861152950562017-09-29T18:15:00.000-07:002017-09-29T18:15:28.967-07:00Communication between Sibling components in Angular<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
Communication or data exchange between component is pretty
common scenario in angular development. We know the property binding and event
binding can be implemented for hierarchical communication, i.e to pass data
from parent to child component and vice versa. We can implement common service scenario
when there is need to communicate among sibling components. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now, the question is can we implement same solution for
parent child communication? The answer is yes, we can because service in
angular is singleton in nature. So, it is single source of truth. <o:p></o:p></div>
<div class="MsoNormal">
Now, let’s implement common service scenario as example.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Step 1) Create multiple component and subscribe common
service in target component</b><o:p></o:p></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal">
Here is example code for that. We will create “SharedService”
shortly. Here is code for “Work1” component.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">import</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> { </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Component</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> } </span><span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">from</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #ce9178; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">'@angular/core'</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">import</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> { </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">SharedService</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> } </span><span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">from</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #ce9178; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">'../services/SharedService'</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: 12.0pt;">
<br /></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">@</span><span style="color: #dcdcaa; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Component</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">({<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">selector:</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #ce9178; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">'work1'</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">,<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">template:</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #ce9178; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">` </span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #ce9178; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> <input
type="text" name="txtName" [(ngModel)]="name"></span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #ce9178; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> <input
type="button" name="Click" value="Click"
(click)="refresh()">`</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">})<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">export</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">class</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #4ec9b0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Work1</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">name</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> : </span><span style="color: #4ec9b0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">string</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">constructor</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">(</span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">private</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">_sharedService</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">: </span><span style="color: #4ec9b0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">SharedService</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> ){<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #dcdcaa; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">refresh</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">(){<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">this</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">.</span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">_sharedService</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">.</span><span style="color: #dcdcaa; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">publishData</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">(</span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">this</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">.</span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">name</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">);<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">}<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Here the idea is, when user will click refresh, it will call
one function in shared service. The function is responsible to push the data in
an observable stream. As soon as service will push the data to stream, the
subscriber of the stream will get notification.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Let’s create another component called “Work2”<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">import</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> { </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Component</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> } </span><span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">from</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #ce9178; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">'@angular/core'</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">import</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> { </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">SharedService</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> } </span><span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">from</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #ce9178; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">'../services/SharedService'</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: 12.0pt;">
<br /></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">@</span><span style="color: #dcdcaa; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Component</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">({<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">selector:</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #ce9178; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">'work2'</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">,<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">template:</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #ce9178; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">`{{name}}`</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">})<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">export</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">class</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #4ec9b0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Work2</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">name</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> : </span><span style="color: #4ec9b0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">string</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">constructor</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">(</span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">private</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">_sharedService</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> : </span><span style="color: #4ec9b0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">SharedService</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">){<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">this</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">.</span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">_sharedService</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">.</span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">name$</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">.</span><span style="color: #dcdcaa; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">subscribe</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">(<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">data</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">=></span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">this</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">.</span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">name</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> = </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">data</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> });<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">}<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Here, you can see that we are subscribing “name” observable
in SharedService. So, when there will be
any change of “name” variable then the code within constructor should trigger.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Step2) Create common service.<o:p></o:p></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now, we will implement the common service which will
function as mediator/event publisher in implementation.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">import</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> { </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Injectable</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> } </span><span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">from</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #ce9178; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">'@angular/core'</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">import</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> { </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Subject</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> } </span><span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">from</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #ce9178; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">'rxjs/Subject'</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">;<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: 12.0pt;">
<br /></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">@</span><span style="color: #dcdcaa; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Injectable</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">()<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #c586c0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">export</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">class</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #4ec9b0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">SharedService</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">private</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">name</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> = </span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">new</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #4ec9b0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">Subject</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"><</span><span style="color: #4ec9b0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">string</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">>(); <o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">name$</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> = </span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">this</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">.</span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">name</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">.</span><span style="color: #dcdcaa; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">asObservable</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">();<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #dcdcaa; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">publishData</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">(</span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">data</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">: </span><span style="color: #4ec9b0; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">string</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">) {<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> </span><span style="color: #569cd6; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">this</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">.</span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">name</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">.</span><span style="color: #dcdcaa; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">next</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">(</span><span style="color: #9cdcfe; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">data</span><span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">);<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<br /></div>
<div class="MsoNormal" style="background: #1E1E1E; line-height: 14.25pt; margin-bottom: .0001pt; margin-bottom: 0in;">
<span style="color: #d4d4d4; font-family: Consolas; font-size: 10.5pt; mso-bidi-font-family: "Times New Roman"; mso-fareast-font-family: "Times New Roman";">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The pushData() function is responsible to push the current
data to “name$” observable stream.<o:p></o:p></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
So, here is final output <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgpXMRcs_ukamiGQIe4VQDN3sqhI9lKSC13gHP6rifoWI9x-6XoHxdz-OpGl2R-OfsPtYs92RdRRimias3MPzydMTBQnybBDPN9_1qpDnUlyRxvHw6edKyjWTx_MLearjHQQs_UCmofo8/s1600/Component_communication_ctrlcvprogrammer.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="198" data-original-width="645" height="122" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgpXMRcs_ukamiGQIe4VQDN3sqhI9lKSC13gHP6rifoWI9x-6XoHxdz-OpGl2R-OfsPtYs92RdRRimias3MPzydMTBQnybBDPN9_1qpDnUlyRxvHw6edKyjWTx_MLearjHQQs_UCmofo8/s400/Component_communication_ctrlcvprogrammer.jpg" width="400" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com10tag:blogger.com,1999:blog-5565818621935638643.post-58440200898014968572017-06-28T02:02:00.000-07:002017-06-28T02:02:05.998-07:00Few Interesting facts of Attribute routing<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;">We of us know that Attribute Routing has introduced to
enhance flexibility of routing in ASP.NET MVC. So, here is my ItemController
which marked as “Item” using routeprefix attribute and GetItem(int Id) action
is decorated using Route attribute. So, to invoke </span></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;">GetItem, the route is
“/Item/1” <o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;"><br /></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> [<span style="color: #2b91af;">RoutePrefix</span>(<span style="color: #a31515;">"Item"</span>)]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">ItemController</span> : <span style="color: #2b91af;">Controller</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> [<span style="color: #2b91af;">Route</span>(<span style="color: #a31515;">"{id}"</span>)]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span>
GetItem(<span style="color: blue;">int</span> Id)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;">Now, let’s think some situation where we want to override
behavior of RoutePrefix. We have defined GetItemInfo() action with Route
attribute prefixed by “~/” which implies that we need to specify “Item” to
invoke the action. So, the route to access GetItemInfo() is <o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;">“<a href="http://localhost:11395/SpecialItem/1"><span style="color: windowtext; text-decoration-line: none;">/SpecialItem/1</span></a>”<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> [<span style="color: #2b91af;">RoutePrefix</span>(<span style="color: #a31515;">"Item"</span>)]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">ItemController</span> : <span style="color: #2b91af;">Controller</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> [<span style="color: #2b91af;">Route</span>(<span style="color: #a31515;">"~/SpecialItem/{id}"</span>)]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span>
GetItemInfo(<span style="color: blue;">int</span> Id)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="font-family: Georgia, Times New Roman, serif;">Set Global Default Route<o:p></o:p></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<b><span style="font-family: Georgia, Times New Roman, serif;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">We know that, in time of
route initialization in config file we can specify default route. Here is
another way to implement same. Just specify “~/” in any action to mark the
action as default action.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">So Route to access
GetItemInfo() is : /<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> [<span style="color: #2b91af;">RoutePrefix</span>(<span style="color: #a31515;">"Item"</span>)]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">ItemController</span> : <span style="color: #2b91af;">Controller</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> [<span style="color: #2b91af;">Route</span>(<span style="color: #a31515;">"~/"</span>)]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span>
GetItemInfo()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">Now, What if we mark
more than one action as default action? You will experience following
exception.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Georgia, Times New Roman, serif; margin-left: 1em; margin-right: 1em;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkqeC5aYN-wxNImktH2H-ErwbXjfl2tHEIno-fiZY4pWiRCwpSapTmsRMJKuEx9rfT-9X8x0UT8R3KInPxXjCKA4m1whMMIw7X9Fh51oyT17fWKY9QcfRGjPiWwyh1FaJr56b5nKseD5I/s1600/1_routing.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="212" data-original-width="551" height="152" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkqeC5aYN-wxNImktH2H-ErwbXjfl2tHEIno-fiZY4pWiRCwpSapTmsRMJKuEx9rfT-9X8x0UT8R3KInPxXjCKA4m1whMMIw7X9Fh51oyT17fWKY9QcfRGjPiWwyh1FaJr56b5nKseD5I/s400/1_routing.jpg" width="400" /></a></span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="MsoNormal">
<b><span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;">Set
Default route to specific RoutePrefix<o:p></o:p></span></span></b></div>
<div class="MsoNormal">
<b><span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;"><br /></span></span></b></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;">If we place Empty string(“”) to some action, it will
mark as default route for that RoutePrefix. So, In following example
GetItemInfo() is default route under “Item” RoutePrefix.<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif;"><a href="http://localhost:11395/Item"><span style="color: windowtext; line-height: 107%; text-decoration-line: none;">So,</span></a><span style="line-height: 107%;">
to Invoke GetItemInfo() the route is “/Item”<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> [<span style="color: #2b91af;">RoutePrefix</span>(<span style="color: #a31515;">"Item"</span>)]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">ItemController</span> : <span style="color: #2b91af;">Controller</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> </span><span style="font-family: Georgia, "Times New Roman", serif;"> </span><span style="font-family: Georgia, "Times New Roman", serif;">[</span><span style="color: #2b91af; font-family: Georgia, "Times New Roman", serif;">Route</span><span style="font-family: Georgia, "Times New Roman", serif;">(</span><span style="color: #a31515; font-family: Georgia, "Times New Roman", serif;">""</span><span style="font-family: Georgia, "Times New Roman", serif;">)]</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> <span style="color: blue;">public</span> <span style="color: blue;">void</span>
GetItemInfo()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;">
}<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;">Here is another way to set default route. <o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> <span style="color: #2b91af;">RoutePrefix</span>(<span style="color: #a31515;">"Item"</span>)]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> [<span style="color: #2b91af;">Route</span>(<span style="color: #a31515;">"{action=GetItemInfo}"</span>)]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> <span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">ItemController</span> : <span style="color: #2b91af;">Controller</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, "Times New Roman", serif;"> </span><span style="color: blue; font-family: Georgia, "Times New Roman", serif;">public</span><span style="font-family: Georgia, "Times New Roman", serif;"> </span><span style="color: blue; font-family: Georgia, "Times New Roman", serif;">void</span><span style="font-family: Georgia, "Times New Roman", serif;">
GetItemInfo()</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, "Times New Roman", serif;"> </span><span style="font-family: Georgia, "Times New Roman", serif;">}</span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;">
}<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;">Route matching by pattern<o:p></o:p></span></span></b></div>
<div class="MsoNormal">
<b><span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;"><br /></span></span></b></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;">Using attribute routing, we can pick route
by pattern. Now, all routes ended with “info” suffix will map to GetItemInfo()
action. So, one sample route could be “/Item/anyinfo”<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">[<span style="color: #2b91af;">RoutePrefix</span>(<span style="color: #a31515;">"Item"</span>)]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
<span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">ItemController</span> : <span style="color: #2b91af;">Controller</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
[<span style="color: #2b91af;">Route</span>(<span style="color: #a31515;">"{*info}"</span>)]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
<span style="color: blue;">public</span> <span style="color: blue;">void</span> GetItemInfo()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;">Set priority to route<o:p></o:p></span></span></b></div>
<div class="MsoNormal">
<b><span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;"><br /></span></span></b></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;">We know that if there are multiple action
mapping to same route, we will get exception. To get rid of from this
situation, we can specify “Order”. In following example we specified Order in “Route”
attribute to action. The route “Item/get/id” is mapping to both GetItemInfo()
and GetAnotherItemInfo().<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"><span style="color: blue;"><br /></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">ItemController</span> : <span style="color: #2b91af;">Controller</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
[<span style="color: #2b91af;">Route</span>(<span style="color: #a31515;">"get/{id}"</span>, Order =0)]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
<span style="color: blue;">public</span> <span style="color: blue;">void</span> GetItemInfo(<span style="color: blue;">int</span> Id)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
[<span style="color: #2b91af;">Route</span>(<span style="color: #a31515;">"get/{id}"</span>, Order = 1)]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
<span style="color: blue;">public</span> <span style="color: blue;">void</span> GetAnotherItemInfo(<span style="color: blue;">int</span> Id)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, Times New Roman, serif;">
}</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, "Times New Roman", serif; text-align: center;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Georgia, "Times New Roman", serif; text-align: center;">If we do not specify “Order”
it will throw this exception.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg75fRsJPYKgt8eVArSKBkiW1oGlGIPh_PV806v1m2iBBF33Ktk8Hw-VqpBg2N0lTHDDoq2TTGia-WJHmNHw-ZPZ2D_3LL8NETy8b11ONt6aZ2pQPzo4GihnRl6j-FpUze8aYPBb2whnnQ/s1600/2_routing.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Georgia, Times New Roman, serif;"><img border="0" data-original-height="194" data-original-width="579" height="133" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg75fRsJPYKgt8eVArSKBkiW1oGlGIPh_PV806v1m2iBBF33Ktk8Hw-VqpBg2N0lTHDDoq2TTGia-WJHmNHw-ZPZ2D_3LL8NETy8b11ONt6aZ2pQPzo4GihnRl6j-FpUze8aYPBb2whnnQ/s400/2_routing.jpg" width="400" /></span></a></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;">MVC, register low order route value at first, we Once
we go with “item/get/1” it will hit GetItemInfo() action.</span></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2H0hkClGGPp922KJ9DsPp8LRw2UGcV9_jr6qaGujX7UfKSFpBhOqvocMqj2VX7SpQ8Ydg1qbkLqS6EUD7rhUZgv7HYdsck_a-t3uttgwU-2LMulmxKA16C7DVA_u-YPK2Cic3Y2nei9E/s1600/3_routing.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Georgia, Times New Roman, serif;"><img border="0" data-original-height="313" data-original-width="599" height="208" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi2H0hkClGGPp922KJ9DsPp8LRw2UGcV9_jr6qaGujX7UfKSFpBhOqvocMqj2VX7SpQ8Ydg1qbkLqS6EUD7rhUZgv7HYdsck_a-t3uttgwU-2LMulmxKA16C7DVA_u-YPK2Cic3Y2nei9E/s400/3_routing.jpg" width="400" /></span></a></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif;"><br /></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman", serif; font-size: 8pt;"><br /></span></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com1tag:blogger.com,1999:blog-5565818621935638643.post-36405609082793199532017-04-02T18:51:00.000-07:002017-04-02T18:51:30.173-07:00Evolution of AJAX World<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggzWYN-wvsTXOY0MvLu8oY2rGZ-ouGZUAyR3pmqUFF-o-zmz6a29gGilG9PoIUfeHMnFVHL1I0VrINLTBq9KE2dBc0Eh5Lv3VL6IL3CI3ihWP6gHVp_zZsLGLNF3ZX_ljHNAZHaTHYp38/s1600/ajax.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggzWYN-wvsTXOY0MvLu8oY2rGZ-ouGZUAyR3pmqUFF-o-zmz6a29gGilG9PoIUfeHMnFVHL1I0VrINLTBq9KE2dBc0Eh5Lv3VL6IL3CI3ihWP6gHVp_zZsLGLNF3ZX_ljHNAZHaTHYp38/s200/ajax.jpg" width="200" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
If you have started you carrier around 7-10 years back as
web developer then probably you have experienced the evaluation practically.</div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Because of huge advantage of AJAX, more or less 70-80 % of
modern web application has adapted this technology. The new style of AJAX
implementation came in market so quickly that it’s sometime hard to remember
what things were before that?<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Anyway, Long ago,
Netscape added a feature in browser called live script which was capable to
give flavor of offline processing like form validation in client side and bit
more. Slowly Live script became JavaScript with more functionality and flexibility.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The inception of DynamicHTML has started in development
world, slowly XML gain its popularity in AJAX world when Microsoft added a
small function in IE5 to perform XMLHttpRequest call to server. <o:p></o:p></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal">
<b>The classic AJAX
using XMLHttpRequest<o:p></o:p></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
This is classic style to make AJAX call using vanilla JavaScript.
If you worked in very old ASP, JSP or PHP application, probably you are familiar
with this style of AJAX call.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;">var xhttp = new XMLHttpRequest();<br style="box-sizing: inherit;" />
xhttp.<span style="box-sizing: inherit;">onreadystatechange</span> = function() {<br style="box-sizing: inherit;" />
if (<span style="box-sizing: inherit;">this</span>.<span style="box-sizing: inherit;">readyState</span> == 4 && this.<span style="box-sizing: inherit;">status</span> == 200) {<br style="box-sizing: inherit;" />
//
Typical action to be performed when the document is ready:<br style="box-sizing: inherit;" />
document.<span style="box-sizing: inherit;">getElementById</span>(<span style="box-sizing: inherit;">"demo"</span>).<span style="box-sizing: inherit;">innerHTML</span> = xhttp.<span style="box-sizing: inherit;">responseText</span>;<br style="box-sizing: inherit;" />
}<br style="box-sizing: inherit;" />
};<br style="box-sizing: inherit;" />
xhttp.<span style="box-sizing: inherit;">open</span>(<span style="box-sizing: inherit;">"GET"</span>, "<i>yourfilename.extension</i>", true);<br style="box-sizing: inherit;" />
xhttp.<span style="box-sizing: inherit;">send</span>();</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Oh, did I miss something? Yes, we need to detect browser
prior to AJAX call, Just to make sure we are using proper XMLHttpRequest
object. Yes, XMLHttpRequest object is browser specific.<o:p></o:p></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal">
<b>JQuery changed the
whole game<o:p></o:p></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Then JQuery came in market, it played major role to change
face of client side app development. It
combine and packed the above code into few lines and introduce the concept of
Callback.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;">$.<span style="box-sizing: inherit;">ajax</span>({url: "yoururl.com", success: function(result){<br style="box-sizing: inherit;" />
//enjoy
with result variable<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"> }});</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
And that’s all, simple, compact, no code smell and maintainable.
Now, in mean time other library too started wrapping classic XMLHttpRequest
request using very similar syntax.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
So, as a result the concept of callback has introduced in development
world. The moto of callback is, call me once you have prepared the result, or
call error in mess!.<o:p></o:p></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal">
<b>Let’s return promise
rather than actual result<o:p></o:p></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
People started to realize that, as it is asynchronous call,
it should return something by which we can take decision. Let’s give some
example. The below code is based on promise and then callback function.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;">requestSomeData("http://example.com ") // returns
a promise for the response<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"><br /></span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"> .then(function(response){
// ‘then’ is used to provide a promise handler<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"> </span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"> return JSON.parse(response.body);
// parse the body<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"> </span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"> }) // returns a
promise for the parsed body<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"><br /></span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"> .then(function(data){<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"> </span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"> return data.something;
// get the price<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"> }) // returns a
promise for the price<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"><br /></span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"> .then(function(price){
// print out the price when it is fulfilled<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"><br /></span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"> //do something
with the data<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"><br /></span></div>
<div class="MsoNormal">
<span style="background-color: #d9ead3;"> });</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We can consider this as fully asynchronous execution plan,
even if my JSON.parse() take huge time, the execution flow will not hang the
thread because I have attached then callback to ensure that someone will take
care once parse completed.<o:p></o:p></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal">
<b>Angular and Other
library utilize it best<o:p></o:p></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Angular 1.X introduced a way to sync all asyn call using “$q”
service. This is huge power to developer to process more than one asynchronous
call and print consolidated result. <o:p></o:p></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal">
<b>Want to have more
control on AJAX call? Use Observable.<o:p></o:p></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
RxJs introduced the concept called Observable to have more
grip on AJAX call. Let’s think that we need to cancel an AJAX call in middle. Assume,
the situation where need to handle multiple AJAX call. Observable is preferred
than promise here.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
So, an observable is like a stream and allow to pass zero or
more events where the callback is called for each event. The Observable covers
more including promise. <o:p></o:p></div>
<div class="MsoNormal">
For more info, please check <i><u>Observable in Angular2</u></i> <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com11tag:blogger.com,1999:blog-5565818621935638643.post-3519913550713062122017-04-01T22:29:00.002-07:002017-04-01T22:29:39.507-07:00Learning Angular2 ? Here you map yourself !<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYk2KvXLYaNAkUi6ZA-6ROXOcbLuocneH4f7cHqsaPdRTuwC0v5ZiNBPKQoD_AybWR94iEOAC66Gx5enHWA92zuC9sDbdO4oF1yhF1-hf9kdFTNNzAlRBrdtjMOJV77F9C_acNa3D8bZo/s1600/angular2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYk2KvXLYaNAkUi6ZA-6ROXOcbLuocneH4f7cHqsaPdRTuwC0v5ZiNBPKQoD_AybWR94iEOAC66Gx5enHWA92zuC9sDbdO4oF1yhF1-hf9kdFTNNzAlRBrdtjMOJV77F9C_acNa3D8bZo/s1600/angular2.jpg" /></a></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></b></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">What is new in angular2?<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> Let's see,
do I really need to learn!<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></b></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Advantages of
angular2<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> If
there, industry will adapt quickly and I have to spend some amount of time to
learn. Good advantages are bad news for "coder by incident" Engineer
:)<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></o:p></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Does typescript
really need in angular2?<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> It could
be gossip, let's check reality. Oh!! People are recommending to use typescript,
so I have to learn it.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></b></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Setting up typescript
environment and start Hello World (before that bit struggle with NPM) <o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> All YouTube
tutorial are using Visual Studio Code, but I want to setup in my Visual Studio
Enterprise edition :)<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></b></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Let’s setup angular2
in Visual Studio <o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> Spent
good amount of time in old angular2 website of Google. Setting up typings.js,
common.js, tsconfig.js
etc finally with webpack, no idea! What is happening! Confused!!</span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></b></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Try angular2 cli or
inbuilt project template with ASP.NET Core 1.0<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> Feel
that ASP.NET Core 1.0 template is best solution, almost 0 setup and production
ready architecture :) <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></b></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Learn architecture of
angular2<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> Let’s
hands on by writing baby component and understand architecture. Learn data
binding, routing, Template, directory bla bla...<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></b></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Dependency injection
in angular2<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> Oh.. Not
much change with angular 1.X, easy to pick up if u know 1.x<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></b></div>
<div class="MsoNormal">
<b><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Now, let's implement
in memory CRUD/TODO app. And here I am... <o:p></o:p></span></b></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0tag:blogger.com,1999:blog-5565818621935638643.post-27484991223201303872016-11-29T20:07:00.002-08:002016-11-29T20:07:52.983-08:00Work with service in Angular2<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
Conceptually service is independent snippet of code which
contains certain functionality or business logic. In Angular2 service is
nothing but class of typescript (If we use typescript) which we can inject to
component or module.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Yes, we can inject service to both component and module
level. In this example we will demonstrate same.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
If you are new in Angular2 , I will recommend to go through
my previous article to setup angular2 project in IDE.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<a href="http://ctrlcvprogrammer.blogspot.com/2016/11/getting-started-with-angular2-with.html">Setup
Angular2 in Visual Studio</a> <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
So, let’s start to implement one simple service which will
return list of Person Object. <o:p></o:p></div>
<div class="MsoNormal">
Add app.dataService.ts file in app folder. Here is content
of file.<o:p></o:p></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">import</span><span style="font-family: Consolas; font-size: 9.5pt;"> {Injectable} </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">from</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"@angular/core"</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">export</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">interface</span><span style="font-family: Consolas; font-size: 9.5pt;"> Person {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
name: </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">@Injectable()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">export</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> dataService{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
getPerson(): Person[]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> [<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> { name: </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"Ram"</span><span style="font-family: Consolas; font-size: 9.5pt;"> },<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> { name: </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"Syam"</span><span style="font-family: Consolas; font-size: 9.5pt;"> },<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> { name: </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"Jodu"</span><span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
];<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;">}</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Here Person interface is type which we are returning from getPerson()
function. Please note that the @Injectable decorator is needed when we want to
inject to some other unit of code. <o:p></o:p></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal">
<b>Inject service to
component<o:p></o:p></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
As we said, service can be injectable both to component and
module. Here we will inject service to component. Here we have created
PersonComponent where we are injecting service in provider section.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">import</span><span style="font-family: Consolas; font-size: 9.5pt;"> {Component} </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">from</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">'@angular/core'</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">import</span><span style="font-family: Consolas; font-size: 9.5pt;"> {dataService ,Person } </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">from</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">'./app.dataservice'</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">import</span><span style="font-family: Consolas; font-size: 9.5pt;"> {OnInit} </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">from</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"@angular/core"</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">@Component({<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
selector: </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">'person'</span><span style="font-family: Consolas; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
template: </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">`<ul></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">
<li *ngFor="let p of _persons">{{p.name}}</li></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">
</ul>`</span><span style="font-family: Consolas; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
providers: [dataService],<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">})<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">export</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> PersonComponent {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> _persons: Person[];<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">constructor</span><span style="font-family: Consolas; font-size: 9.5pt;">(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">private</span><span style="font-family: Consolas; font-size: 9.5pt;"> _dataService:
dataService)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">this</span><span style="font-family: Consolas; font-size: 9.5pt;">._persons = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">this</span><span style="font-family: Consolas; font-size: 9.5pt;">._dataService.getPerson();<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal">
In constructor we are consuming getPerson() function which
populating _Person member. Now, let’s create a view to display the component.
Here is our sample view.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">!DOCTYPE</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt;">html</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">html</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">head</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt;">lang</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">="en"></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">base</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt;">href</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">="/"></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">meta</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt;">charset</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">="UTF-8"></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">meta</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt;">name</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">="viewport"</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt;">content</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">="width=device-width,
initial-scale=1"></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: darkgreen; font-family: Consolas; font-size: 9.5pt;"><!--
Polyfill(s) for older browsers --></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">script</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt;">src</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">="node_modules/core-js/client/shim.min.js"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">script</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">script</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt;">src</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">="node_modules/zone.js/dist/zone.js"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">script</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">script</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt;">src</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">="node_modules/reflect-metadata/Reflect.js"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">script</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">script</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt;">src</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">="node_modules/systemjs/dist/system.src.js"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">script</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: darkgreen; font-family: Consolas; font-size: 9.5pt;"><!--
Configure SystemJS --></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">script</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: red; font-family: Consolas; font-size: 9.5pt;">src</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">="systemjs.config.js"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">script</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">script</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
System.import(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">'app'</span><span style="font-family: Consolas; font-size: 9.5pt;">).catch(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">function</span><span style="font-family: Consolas; font-size: 9.5pt;">(err){ console.error(err); });<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">script</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">head</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">body</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">person</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">></span><span style="font-family: Consolas; font-size: 9.5pt;">Loading App...</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">person</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt;">body</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"></</span><span style="color: maroon; font-family: Consolas; font-size: 9.5pt; line-height: 107%;">html</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%;">></span><o:p></o:p></div>
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Once we run the application
,we will see that data is showing like this.</div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihVnwr_xzCdThJZZPkvwc_MPKEOfLwBGZdYSI4yeY9ennRxIqfpVFS7BolPKXC4GU0hMU7fXG04x9nHA4wIHr1JqNCdQ3NuBbi2GbV0rqEVOXleKEulpzCHifz5_JMxYLPmy1hRy-6UtQ/s1600/Service.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="143" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihVnwr_xzCdThJZZPkvwc_MPKEOfLwBGZdYSI4yeY9ennRxIqfpVFS7BolPKXC4GU0hMU7fXG04x9nHA4wIHr1JqNCdQ3NuBbi2GbV0rqEVOXleKEulpzCHifz5_JMxYLPmy1hRy-6UtQ/s400/Service.png" width="400" /></a></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal">
<b>Inject service in
module<o:p></o:p></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now, let’s see how we can inject service to module. Here
mainModule of application where we are injecting service in provider section. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">import</span><span style="font-family: Consolas; font-size: 9.5pt;"> { NgModule } </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">from</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">'@angular/core'</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">import</span><span style="font-family: Consolas; font-size: 9.5pt;"> { BrowserModule } </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">from</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">'@angular/platform-browser'</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">import</span><span style="font-family: Consolas; font-size: 9.5pt;"> { PersonComponent } </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">from</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">'./app.main_component'</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">import</span><span style="font-family: Consolas; font-size: 9.5pt;"> { dataService} </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">from</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">'./app.dataservice'</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">@NgModule({<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
imports: [BrowserModule ],<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
declarations: [PersonComponent],<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
bootstrap: [PersonComponent],<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
providers: [dataService]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">})<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">export</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> mainModule<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;">};</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now, we can use the service in PersonComponent without
inject it. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">import</span><span style="font-family: Consolas; font-size: 9.5pt;"> {Component} </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">from</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">'@angular/core'</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">import</span><span style="font-family: Consolas; font-size: 9.5pt;"> {dataService, Person } </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">from</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">'./app.dataservice'</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">import</span><span style="font-family: Consolas; font-size: 9.5pt;"> {OnInit} </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">from</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"@angular/core"</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">@Component({<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
selector: </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">'person'</span><span style="font-family: Consolas; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
template: </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">`<ul></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">
<li *ngFor="let p of _persons">{{p.name}}</li></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">
</ul>`</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">})<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">export</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> PersonComponent {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> _persons: Person[];<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">constructor</span><span style="font-family: Consolas; font-size: 9.5pt;">(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">private</span><span style="font-family: Consolas; font-size: 9.5pt;"> _dataService:
dataService) {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">this</span><span style="font-family: Consolas; font-size: 9.5pt;">._persons = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">this</span><span style="font-family: Consolas; font-size: 9.5pt;">._dataService.getPerson();<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
console.log(JSON.stringify(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">this</span><span style="font-family: Consolas; font-size: 9.5pt;">._persons));<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com6tag:blogger.com,1999:blog-5565818621935638643.post-82811973599826409492016-11-28T20:32:00.001-08:002016-11-28T20:32:34.696-08:00Main and Feature module in Angular2<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">We can assume Module as root node in angular2 application. A module
may contains components (one or more), pipes, services which is logically
related to some module. For example, if we create login module then probably
login component, sign in component, logout component will be child of login
module. So we can say that those component will hook up with login module.
Again, those component may use login service, logout service etc. which again
logically related to login functionality and can be inject to login module.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> Point to be noted that each
angular2 application should have at least one module which will load in
bootstrap to startup the application. We can call the module as main module. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The application may contains many sub module to support business
functionality and those module could be call as feature module.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The feature module will attach to main module so that it will be accessible
in application. To make available one module to other module we have to export
it. The consumer module have to import same to consume it.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">In this small example we will learn to attach one feature module to
main module. I am assuming that you have Angular2 setup in your editor. If not
please follow my previous article for step to step guide of angular setup.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><a href="http://ctrlcvprogrammer.blogspot.in/2016/11/getting-started-with-angular2-with.html">Step
to Step Guide of angular2 setup in Visual Studio.</a><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Now, follow the steps to implement same.<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The entire folder structure will be like this.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8FRUcLiHaLrvNrYq9vm3cxPKDrQ-kQQRfH_LSkD0anIWcXttWyQiyEWK7TBq2aqWh7mq1DtlhUq7GPnptkTPimC7c8m57kH-Ti_kuUE4-0iWTz6-aP05uafqELlPD6IxAjRUWBXWFnfs/s1600/Angular2Setup_1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8FRUcLiHaLrvNrYq9vm3cxPKDrQ-kQQRfH_LSkD0anIWcXttWyQiyEWK7TBq2aqWh7mq1DtlhUq7GPnptkTPimC7c8m57kH-Ti_kuUE4-0iWTz6-aP05uafqELlPD6IxAjRUWBXWFnfs/s400/Angular2Setup_1.png" width="228" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Step1) Create main component. </b><o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Create “app.main_component.ts” file under app folder of application. <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">import</span> {Component} <span style="color: blue;">from</span> <span style="color: #a31515;">'@angular/core'</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">import</span> {OnInit} <span style="color: blue;">from</span> <span style="color: #a31515;">"@angular/core"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">@Component({<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
selector: <span style="color: #a31515;">'welcome'</span>,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
template: <span style="color: #a31515;">`<p>{{message}}</p> <login></login>`</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">})<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">export</span> <span style="color: blue;">class</span> welcomeComponent {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: blue;">private</span> message: <span style="color: blue;">string</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: blue;">constructor</span>() {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: blue;">this</span>.message = <span style="color: #a31515;">"Welcome to
app."</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Just notice that we have used “<login></login>” element
in template section which is defined in our feature module which we will
implement in steps.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Step2) Create main module.</b><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Add main.ts under app folder in application and here is
implementation. <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">import</span> { NgModule } <span style="color: blue;">from</span> <span style="color: #a31515;">'@angular/core'</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">import</span> { BrowserModule } <span style="color: blue;">from</span> <span style="color: #a31515;">'@angular/platform-browser'</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">import</span> { welcomeComponent } <span style="color: blue;">from</span> <span style="color: #a31515;">'./app.main_component'</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">import</span> {loginModule} <span style="color: blue;">from</span> <span style="color: #a31515;">'./app.login_module'</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">@NgModule({<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
imports: [BrowserModule , loginModule],<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
declarations: [welcomeComponent],<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
bootstrap: [welcomeComponent]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">})<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">export</span> <span style="color: blue;">class</span> mainModule<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="line-height: 107%;">};</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Just notice that we have imported our feature module called “loginModule”
in imports section of main module. The loginModule we will define in short.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Step 3) Setup main module for bootstrap.</b><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Here is code to setup mainModule in bootstrap method. So mainModule
will trigger when application will load first time. The file name is “main.ts”<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">import</span> {platformBrowserDynamic} <span style="color: blue;">from</span> <span style="color: #a31515;">'@angular/platform-browser-dynamic'</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">import</span> {mainModule} <span style="color: blue;">from</span> <span style="color: #a31515;">'./app.main_module'</span>;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="line-height: 107%;">platformBrowserDynamic().bootstrapModule(mainModule);</span><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Step 4) now we will concentrate in feature module <o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Add “app.login_component” file under app folder. The loginComponent contains very simple
template, We can implement real time login template and handle event in real
application.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">import</span> {Component} <span style="color: blue;">from</span> <span style="color: #a31515;">'@angular/core'</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">@Component({<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
selector: <span style="color: #a31515;">'login'</span>,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
template: <span style="color: #a31515;">'<p> Welcome to login section..</p>'</span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">})<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">export</span> <span style="color: blue;">class</span> loginComponent {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Step 5 ) Add login module <o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Add “app.login_module.ts” file under app folder. The login module is
linked with loginComponent. In need we can attach more login/logout related
component with this module <o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">import</span> { NgModule } <span style="color: blue;">from</span> <span style="color: #a31515;">'@angular/core'</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">import</span> {loginComponent } <span style="color: blue;">from</span> <span style="color: #a31515;">'./app.login_component'</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">import</span> { CommonModule } <span style="color: blue;">from</span> <span style="color: #a31515;">'@angular/common'</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">@NgModule({<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
imports: [CommonModule],<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
declarations: [loginComponent],<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
exports: [loginComponent]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">})<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;">export</span> <span style="color: blue;">class</span> loginModule {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="line-height: 107%;">};</span><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Step 6) The last step is to create “index.html” page. And set it as
startup page.</b><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;"><</span><span style="color: maroon;">!DOCTYPE</span> <span style="color: red;">html</span><span style="color: blue;">></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;"><</span><span style="color: maroon;">html</span><span style="color: blue;">></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;"><</span><span style="color: maroon;">head</span> <span style="color: red;">lang</span><span style="color: blue;">="en"></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: blue;"><</span><span style="color: maroon;">base</span> <span style="color: red;">href</span><span style="color: blue;">="/"></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: blue;"><</span><span style="color: maroon;">meta</span> <span style="color: red;">charset</span><span style="color: blue;">="UTF-8"></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: blue;"><</span><span style="color: maroon;">meta</span> <span style="color: red;">name</span><span style="color: blue;">="viewport"</span> <span style="color: red;">content</span><span style="color: blue;">="width=device-width,
initial-scale=1"></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: darkgreen;"><!--
Polyfill(s) for older browsers --></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: blue;"><</span><span style="color: maroon;">script</span> <span style="color: red;">src</span><span style="color: blue;">="node_modules/core-js/client/shim.min.js"></</span><span style="color: maroon;">script</span><span style="color: blue;">></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: blue;"><</span><span style="color: maroon;">script</span> <span style="color: red;">src</span><span style="color: blue;">="node_modules/zone.js/dist/zone.js"></</span><span style="color: maroon;">script</span><span style="color: blue;">></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: blue;"><</span><span style="color: maroon;">script</span> <span style="color: red;">src</span><span style="color: blue;">="node_modules/reflect-metadata/Reflect.js"></</span><span style="color: maroon;">script</span><span style="color: blue;">></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: blue;"><</span><span style="color: maroon;">script</span> <span style="color: red;">src</span><span style="color: blue;">="node_modules/systemjs/dist/system.src.js"></</span><span style="color: maroon;">script</span><span style="color: blue;">></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: darkgreen;"><!--
Configure SystemJS --></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: blue;"><</span><span style="color: maroon;">script</span> <span style="color: red;">src</span><span style="color: blue;">="systemjs.config.js"></</span><span style="color: maroon;">script</span><span style="color: blue;">></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: blue;"><</span><span style="color: maroon;">script</span><span style="color: blue;">></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
System.import(<span style="color: #a31515;">'app'</span>).catch(<span style="color: blue;">function</span>(err){ console.error(err); });<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: blue;"></</span><span style="color: maroon;">script</span><span style="color: blue;">></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;"></</span><span style="color: maroon;">head</span><span style="color: blue;">></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;"><</span><span style="color: maroon;">body</span><span style="color: blue;">></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
<span style="color: blue;"><</span><span style="color: maroon;">welcome</span><span style="color: blue;">></span>Loading App...<span style="color: blue;"></</span><span style="color: maroon;">welcome</span><span style="color: blue;">></span><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue;"></</span><span style="color: maroon;">body</span><span style="color: blue;">></span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue; line-height: 107%;"></</span><span style="color: maroon; line-height: 107%;">html</span><span style="color: blue; line-height: 107%;">></span><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><b>Step 7) Run and Fun!!</b><o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPJMP44S4bNWwa-RZDsg2WwICEo6CltrAm-Qkmz2ctnaV1lN0qiyi6_mIaRIeqb4gtrPpqMtJgZmHj63IOszXMpLGHBtnOvE_4ILA-VtQPVGt-AJlGlSbgi2rIA2_nGmrYQOSPMaKv_N8/s1600/Angular2Setup_2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><img border="0" height="146" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPJMP44S4bNWwa-RZDsg2WwICEo6CltrAm-Qkmz2ctnaV1lN0qiyi6_mIaRIeqb4gtrPpqMtJgZmHj63IOszXMpLGHBtnOvE_4ILA-VtQPVGt-AJlGlSbgi2rIA2_nGmrYQOSPMaKv_N8/s400/Angular2Setup_2.png" width="400" /></span></a></div>
<div class="MsoNormal">
<b><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></b></div>
<div class="MsoNormal">
<span style="font-family: "Calibri Light",sans-serif; mso-ascii-theme-font: major-latin; mso-bidi-font-family: Consolas; mso-hansi-theme-font: major-latin;"><br /></span></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0tag:blogger.com,1999:blog-5565818621935638643.post-23544568611903323462016-11-26T21:52:00.000-08:002016-11-26T22:22:29.010-08:00Getting started with Angular2 with ASP.NET<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
This is hello world article we will learn to setup Asngular2
application in ASP.NET Environment. We are using Visual Studio 2015 as IDE. You
may use some other but make sure to provide proper setting in “tsconfig.json” file
(which we will discuss later on)<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
From my personal
experience I feel that choosing proper version in angular2 is bit confusing. If
you try with beta or RC version some feature may not support. Please make sure
to check angular2 version before implementing any new feature.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
In this example we are using 2.0.0 version of angular and
proper version of dependent components. So let’s start to follow few steps to
implement hello world in Angular2.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<span style="font-family: "calibri" , sans-serif; font-size: 11.0pt; line-height: 107%;"><b>Step 1) Choose ASP.NET project Template. We
could choose ASP.NET Core as well.</b></span><br />
<span style="font-family: "calibri" , sans-serif; font-size: 11.0pt; line-height: 107%;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVNI_AIwX-IEEbyuEfhz8hCPkRyr5e6xeRYjEZe17Xn0gm6W9k79QWpU-TdNf65ky7Iy5cavsLDiFtsg5Rf587ol5-D7Km5fMRU_g27RM95j37UkZat87cSC58wxsoyJ3g13g0DXK9Txc/s1600/Angular2-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="206" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVNI_AIwX-IEEbyuEfhz8hCPkRyr5e6xeRYjEZe17Xn0gm6W9k79QWpU-TdNf65ky7Iy5cavsLDiFtsg5Rf587ol5-D7Km5fMRU_g27RM95j37UkZat87cSC58wxsoyJ3g13g0DXK9Txc/s400/Angular2-1.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="MsoNormal">
<b>Step 2) Add package.json in application. Here is content of
package.json file.</b><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"name"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"sample app"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"version"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"1.0.0"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"author"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"Sourav Kayal"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"description"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"Just hello World."</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"scripts"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"start"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"tsc &&
concurrently \"tsc -w\" \"lite-server\" "</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"tsc"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"tsc"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"tsc:w"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"tsc -w"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"lint"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"tslint
./app/**/*.ts -t verbose"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"lite"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"lite-server"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"typings"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"typings"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"postinstall"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"typings
install"</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
},<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"license"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"ISC"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"dependencies"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"@angular/common"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"2.0.0"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"@angular/compiler"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"2.0.0"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"@angular/core"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"2.0.0"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"@angular/forms"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"2.0.0"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"@angular/http"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"2.0.0"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"@angular/platform-browser"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"2.0.0"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"@angular/platform-browser-dynamic"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"2.0.0"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"@angular/router"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"3.0.0"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"core-js"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"^2.4.1"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"reflect-metadata"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"^0.1.3"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"rxjs"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"5.0.0-beta.12"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"systemjs"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"0.19.27"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"zone.js"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"^0.6.23"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"bootstrap"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"^3.3.6"</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
},<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"devDependencies"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"concurrently"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"^2.2.0"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"lite-server"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"^2.2.0"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"tslint"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"^3.7.4"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"typescript"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"^2.0.2"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"typings"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"^1.0.4"</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
},<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"repository"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: {}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">}</span><o:p></o:p></div>
<div class="MsoNormal">
<span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<b>Step 2) Add tsconfig.json file and here is content.</b><o:p></o:p></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"compilerOptions"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"target"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"es5"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"module"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"commonjs"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"moduleResolution"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"node"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"sourceMap"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">true</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"emitDecoratorMetadata"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">true</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"experimentalDecorators"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">true</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"removeComments"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">false</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"noImplicitAny"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">true</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"suppressImplicitAnyIndexErrors"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">true</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
},<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"compileOnSave"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">true</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"exclude"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: [<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"node_modules"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"wwwroot"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"Scripts/app"</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">}</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The exclude section of this file depends on the IDE where
you are developing application. In case of Visual Studio 2015 the setting is
like this.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Step 3 ) Add systemjs.config.js file in application and here
is the content</b><o:p></o:p></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;">/**<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;"> * System configuration for Angular 2 samples<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;"> * Adjust as necessary for your application
needs.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: green; font-family: "consolas"; font-size: 9.5pt;"> */</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">(</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">function</span><span style="font-family: "consolas"; font-size: 9.5pt;"> (global) {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
System.config({<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
paths: {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//
paths serve as alias</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'npm:'</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'node_modules/'</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
},<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//
map tells the System loader where to look for things</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
map: {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//
our app is within the app folder</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
app: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'app'</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//
angular bundles</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'@angular/core'</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'npm:@angular/core/bundles/core.umd.js'</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'@angular/common'</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'npm:@angular/common/bundles/common.umd.js'</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'@angular/compiler'</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'npm:@angular/compiler/bundles/compiler.umd.js'</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'@angular/platform-browser'</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'npm:@angular/platform-browser/bundles/platform-browser.umd.js'</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'@angular/platform-browser-dynamic'</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js'</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'@angular/http'</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'npm:@angular/http/bundles/http.umd.js'</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'@angular/router'</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'npm:@angular/router/bundles/router.umd.js'</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'@angular/forms'</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'npm:@angular/forms/bundles/forms.umd.js'</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//
other libraries</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'rxjs'</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'npm:rxjs'</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
},<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: green; font-family: "consolas"; font-size: 9.5pt;">//
packages tells the System loader how to load when no filename and/or no
extension</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
packages: {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
app: {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
main: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'./main.js'</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
defaultExtension: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'js'</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
},<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
rxjs: {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
defaultExtension: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'js'</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
});<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">})(</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">this</span><span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">);</span><o:p></o:p></div>
<div class="MsoNormal">
<span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
In app sub section under packages we have referred main.js
file. Which indicates that this file is our entry point of application and load
first.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b> Step 4) Add
typings.json file with this content</b><o:p></o:p></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"globalDependencies"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"core-js"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"registry:dt/core-js#0.0.0+20160725163759"</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: #2e75b6; font-family: "consolas"; font-size: 9.5pt;">"node"</span><span style="font-family: "consolas"; font-size: 9.5pt;">: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">"registry:dt/node#6.0.0+20160831021119"</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">}</span><o:p></o:p></div>
<div class="MsoNormal">
<span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
Here we have complete our environment setup for Angular2.
Now we will concentrate on Application setup.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Step 5) Add app.component.ts under app folder and add below
content.</b><o:p></o:p></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">import</span><span style="font-family: "consolas"; font-size: 9.5pt;"> {Component} </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">from</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'@angular/core'</span><span style="font-family: "consolas"; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">@Component({<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
selector: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'my-app'</span><span style="font-family: "consolas"; font-size: 9.5pt;">,<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
template: </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'<h1>Hello World :)</h1>'</span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">})<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">export</span><span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;"> </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">class</span><span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">
AppComponent { }</span> <o:p></o:p></div>
<div class="MsoNormal">
<span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<b>Step 6) Add app.module.ts file under app folder with below
content.</b><o:p></o:p></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">import</span><span style="font-family: "consolas"; font-size: 9.5pt;"> { NgModule } </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">from</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'@angular/core'</span><span style="font-family: "consolas"; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">import</span><span style="font-family: "consolas"; font-size: 9.5pt;"> { BrowserModule } </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">from</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'@angular/platform-browser'</span><span style="font-family: "consolas"; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">import</span><span style="font-family: "consolas"; font-size: 9.5pt;"> { AppComponent } </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">from</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'./app.component'</span><span style="font-family: "consolas"; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">@NgModule({<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
imports: [BrowserModule],<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
declarations: [AppComponent],<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
bootstrap: [AppComponent]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">})<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">export</span><span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;"> </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">class</span><span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">
AppModule { };</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Step7)
Add main.ts file under app folder with below content<o:p></o:p></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">import</span><span style="font-family: "consolas"; font-size: 9.5pt;"> {platformBrowserDynamic} </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">from</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'@angular/platform-browser-dynamic'</span><span style="font-family: "consolas"; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">import</span><span style="font-family: "consolas"; font-size: 9.5pt;"> {AppModule} </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">from</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'./app.module'</span><span style="font-family: "consolas"; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">platformBrowserDynamic().bootstrapModule(AppModule);</span><o:p></o:p></div>
<div class="MsoNormal">
<span style="font-family: "consolas"; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoNormal">
So the entire directory structure will look like this<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSWtiInTblSuBoy79ohrT9TV6lDwk2hR5_3wY3q2lZiapyVLWTl40uq6VL9JP7Sf0pYBX0qT7jGtTFQarKxkP0PfrUb3uhWyeo9I1lLWBzDb2a6C6lyz6rvQ4eZTWYnlcsX9J1FtGnVoo/s1600/Angular2-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSWtiInTblSuBoy79ohrT9TV6lDwk2hR5_3wY3q2lZiapyVLWTl40uq6VL9JP7Sf0pYBX0qT7jGtTFQarKxkP0PfrUb3uhWyeo9I1lLWBzDb2a6C6lyz6rvQ4eZTWYnlcsX9J1FtGnVoo/s320/Angular2-2.png" width="177" /></a></div>
<span style="font-family: "calibri" , sans-serif; font-size: 11.0pt; line-height: 107%;"><br /></span>
<br />
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Step 8) Add index.html page in application. Here is content
of same.</b><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">!DOCTYPE</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: red; font-family: "consolas"; font-size: 9.5pt;">html</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">html</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">head</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: red; font-family: "consolas"; font-size: 9.5pt;">lang</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">="en"></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">base</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: red; font-family: "consolas"; font-size: 9.5pt;">href</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">="/"></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">title</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"></</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">title</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">meta</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: red; font-family: "consolas"; font-size: 9.5pt;">charset</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">="UTF-8"></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">meta</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: red; font-family: "consolas"; font-size: 9.5pt;">name</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">="viewport"</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: red; font-family: "consolas"; font-size: 9.5pt;">content</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">="width=device-width,
initial-scale=1"></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: darkgreen; font-family: "consolas"; font-size: 9.5pt;"><!--
Polyfill(s) for older browsers --></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">script</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: red; font-family: "consolas"; font-size: 9.5pt;">src</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">="node_modules/core-js/client/shim.min.js"></</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">script</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">script</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: red; font-family: "consolas"; font-size: 9.5pt;">src</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">="node_modules/zone.js/dist/zone.js"></</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">script</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">script</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: red; font-family: "consolas"; font-size: 9.5pt;">src</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">="node_modules/reflect-metadata/Reflect.js"></</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">script</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">script</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: red; font-family: "consolas"; font-size: 9.5pt;">src</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">="node_modules/systemjs/dist/system.src.js"></</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">script</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: darkgreen; font-family: "consolas"; font-size: 9.5pt;"><!--
Configure SystemJS --></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">script</span><span style="font-family: "consolas"; font-size: 9.5pt;"> </span><span style="color: red; font-family: "consolas"; font-size: 9.5pt;">src</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">="systemjs.config.js"></</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">script</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">script</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
System.import(</span><span style="color: #a31515; font-family: "consolas"; font-size: 9.5pt;">'app'</span><span style="font-family: "consolas"; font-size: 9.5pt;">).catch(</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">function</span><span style="font-family: "consolas"; font-size: 9.5pt;">(err){ console.error(err); });<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"></</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">script</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"></</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">head</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">body</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "consolas"; font-size: 9.5pt;">
</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"><</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">my-app</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;">Welcome.</span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"></</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">my-app</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt;"></</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt;">body</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt;">></span><span style="font-family: "consolas"; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt; line-height: 107%;"></</span><span style="color: maroon; font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">html</span><span style="color: blue; font-family: "consolas"; font-size: 9.5pt; line-height: 107%;">></span><o:p></o:p></div>
<div class="MsoNormal">
<span style="color: blue; font-family: "consolas"; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<span style="font-family: "calibri" , sans-serif; font-size: 11.0pt; line-height: 107%;">
</span><br />
<div class="MsoNormal">
<b>Step 9) Hit F5 and Cheers!!!</b><o:p></o:p></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNBPrwMTnK60FJVSnmbxsyQkumvXu54sM7gAgQgRuY7lriYZ3lbEcZNQ8pg4MrQ6PMaJD79IvD7FmS1uycH3hjwPTKQmYJpBt-R3E0at-GT-9JbUGzzYNi-7UWCHOXV6sdqt5jymMaBs0/s1600/Angular2-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="163" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjNBPrwMTnK60FJVSnmbxsyQkumvXu54sM7gAgQgRuY7lriYZ3lbEcZNQ8pg4MrQ6PMaJD79IvD7FmS1uycH3hjwPTKQmYJpBt-R3E0at-GT-9JbUGzzYNi-7UWCHOXV6sdqt5jymMaBs0/s400/Angular2-3.png" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="MsoNormal">
<b>PS :</b> Please do not change file name anywhere if you are not
aware of subsequent following change. This
just hello world guide in Angular2. To understand meaning of code and execution
sequence please follow any good tutorial.<o:p></o:p><br />
<br />
<a href="https://www.youtube.com/watch?v=oMgvi-AV-eY" target="_blank"><b>Please follow this tutorial to learn basic of Angular2</b></a><br />
<br /></div>
<span style="font-family: "calibri" , sans-serif; font-size: 11.0pt; line-height: 107%;"><br /></span></div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com1tag:blogger.com,1999:blog-5565818621935638643.post-26312617081789918312016-11-12T04:42:00.000-08:002016-11-12T04:42:43.286-08:00Extensible point of MVC: Custom response type in MVC and WebAPI<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt;">We know that MVC has many
extensible point where we can hook up our custom code and change normal behavior
of framework. Those implementations are really helpful when default framework
is not able to meet our requirement.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt;"><br /></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt;">In this article we will implement
custom return type both in MVC and WebAPI. Those implementation could be
helpful when we want to modify return type based on application’s demand. <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt;"><b>Custom return type in MVC<o:p></o:p></b></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt;">We know that ActionResult is base
class of all return type in MVC. Return type like ViewResult, JsonResult ,
EmptyResutl etc are derived from ActionResult. We can derive our return type
from ActionResult class as well.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt;">Let’s think some use case where we
want to limit return items in response message. For example we have list of
objects and on demand we will decide how many objects we will return.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt;">Though there are many ways like result
filter , OData are there to implement such scenario but we can use custom
response type too to implement.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
</div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt;">Here we have LimitResult class
which is derived from ActionResult. Within constructor we care filtering out
items based on value of “Count”. <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">LimitResult</span><span style="font-family: Consolas; font-size: 9.5pt;"> : </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">ActionResult</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Dictionary</span><span style="font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">int</span><span style="font-family: Consolas; font-size: 9.5pt;">, </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;">> _disc = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Dictionary</span><span style="font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">int</span><span style="font-family: Consolas; font-size: 9.5pt;">, </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;">>();<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> LimitResult(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">List</span><span style="font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;">> list, </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> Count)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">foreach</span><span style="font-family: Consolas; font-size: 9.5pt;"> (</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">var</span><span style="font-family: Consolas; font-size: 9.5pt;"> item </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">in</span><span style="font-family: Consolas; font-size: 9.5pt;"> list.Take(Count))<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> _disc.Add(item.Id, item);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }
<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">override</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">void</span><span style="font-family: Consolas; font-size: 9.5pt;"> ExecuteResult(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">ControllerContext</span><span style="font-family: Consolas; font-size: 9.5pt;"> context)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HttpResponseBase</span><span style="font-family: Consolas; font-size: 9.5pt;"> response =
context.HttpContext.Response;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> response.ContentType = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"application/json"</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> response.Write(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">JsonConvert</span><span style="font-family: Consolas; font-size: 9.5pt;">.SerializeObject(
_disc));<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: "Times New Roman",serif; font-size: 12.0pt;">Now, We will use the custom class as
response from action.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">int</span><span style="font-family: Consolas; font-size: 9.5pt;"> Id { </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">get</span><span style="font-family: Consolas; font-size: 9.5pt;">; </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">set</span><span style="font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> Name { </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">get</span><span style="font-family: Consolas; font-size: 9.5pt;">; </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">set</span><span style="font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HomeController</span><span style="font-family: Consolas; font-size: 9.5pt;"> : </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Controller</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">ActionResult</span><span style="font-family: Consolas; font-size: 9.5pt;"> Index()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">List</span><span style="font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;">> person = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">List</span><span style="font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;">>();<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> person.Add(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;"> { Id = 1, Name = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"Sourav"</span><span style="font-family: Consolas; font-size: 9.5pt;"> });<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> person.Add(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;"> { Id = 2, Name = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"Kayal"</span><span style="font-family: Consolas; font-size: 9.5pt;"> });<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">LimitResult</span><span style="font-family: Consolas; font-size: 9.5pt;">(person , 1);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
</div>
<div class="MsoNormal">
We are seeing that only one item has returned because we set
that only 1 result is allowed in response.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieW2Q4uB3qpwUrKjSyOuBkRhCZ1DrN58pYQnu3zGnTXClgaOpvTlomMB9OHcHhF8uRZsQ7r_dWWJThowwOePK0RkjYO4uTv4Rctqfy4jTlVgLLmy181EVZeh59HXJFw3P9XgHdVxDd3Ng/s1600/CustomReturnType_1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="107" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieW2Q4uB3qpwUrKjSyOuBkRhCZ1DrN58pYQnu3zGnTXClgaOpvTlomMB9OHcHhF8uRZsQ7r_dWWJThowwOePK0RkjYO4uTv4Rctqfy4jTlVgLLmy181EVZeh59HXJFw3P9XgHdVxDd3Ng/s400/CustomReturnType_1.jpg" width="400" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Custom Result in WebAPI 2 <o:p></o:p></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We know that Web API 2 supports IHttpActionResult as type.
Though we can use HttpResponse as return type. In this example we will implement
IHttpActionResult in our custom response class. Here we have wrap
ForbiddenResult class and InternalServerErrorResult class by CustomResultApiController
class.</div>
<div class="MsoNormal">
<span style="font-family: Calibri, sans-serif; font-size: 11pt; text-align: center;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Calibri, sans-serif; font-size: 11pt; text-align: center;">So, the CustomResultApiController looks like a
package of custom response type. </span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">abstract</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">CustomResultApiController</span><span style="font-family: Consolas; font-size: 9.5pt;"> : </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">ApiController</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">ForbiddenResult</span><span style="font-family: Consolas; font-size: 9.5pt;"> : </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">IHttpActionResult</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">private</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">readonly</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HttpRequestMessage</span><span style="font-family: Consolas; font-size: 9.5pt;"> _request;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">private</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">readonly</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> _reason;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> ForbiddenResult(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HttpRequestMessage</span><span style="font-family: Consolas; font-size: 9.5pt;"> request, </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> reason)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> _request = request;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> _reason = reason;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> ForbiddenResult(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HttpRequestMessage</span><span style="font-family: Consolas; font-size: 9.5pt;"> request)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> _request = request;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> _reason = </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"Forbidden"</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Task</span><span style="font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HttpResponseMessage</span><span style="font-family: Consolas; font-size: 9.5pt;">> ExecuteAsync(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">CancellationToken</span><span style="font-family: Consolas; font-size: 9.5pt;"> cancellationToken)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">var</span><span style="font-family: Consolas; font-size: 9.5pt;"> response = _request.CreateResponse(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HttpStatusCode</span><span style="font-family: Consolas; font-size: 9.5pt;">.Forbidden, _reason);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Task</span><span style="font-family: Consolas; font-size: 9.5pt;">.FromResult(response);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">InternalServerErrorResult</span><span style="font-family: Consolas; font-size: 9.5pt;"> : </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">IHttpActionResult</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">private</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">readonly</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HttpRequestMessage</span><span style="font-family: Consolas; font-size: 9.5pt;"> _request;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">private</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">readonly</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> _errormessage;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> InternalServerErrorResult(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HttpRequestMessage</span><span style="font-family: Consolas; font-size: 9.5pt;"> request, </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> error)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> _request = request;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> _errormessage = error;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Task</span><span style="font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HttpResponseMessage</span><span style="font-family: Consolas; font-size: 9.5pt;">> ExecuteAsync(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">CancellationToken</span><span style="font-family: Consolas; font-size: 9.5pt;"> cancellationToken)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">var</span><span style="font-family: Consolas; font-size: 9.5pt;"> response = _request.CreateResponse(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HttpStatusCode</span><span style="font-family: Consolas; font-size: 9.5pt;">.InternalServerError,
_errormessage);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Task</span><span style="font-family: Consolas; font-size: 9.5pt;">.FromResult(response);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The IHttpActionResult interface contains ExecuteAsync()
function and we have implemented in both classes. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Here is how, we can use our custom classes as response object.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HomeController</span><span style="font-family: Consolas; font-size: 9.5pt;"> : </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">CustomResultApiController</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
[System.Web.Http.</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HttpGet</span><span style="font-family: Consolas; font-size: 9.5pt;">]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">IHttpActionResult</span><span style="font-family: Consolas; font-size: 9.5pt;"> Forbidded()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">ForbiddenResult</span><span style="font-family: Consolas; font-size: 9.5pt;">(Request, </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"My Custom
Reason"</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }</span><o:p></o:p></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
We are seeing that the response message is embedded in body
of response object.<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1XL_f3NcrQIFOXLzxUcKYHa6sHIkvp04uk9Fj9SAyRk4m2ewO_78V8_XylIk3YRWI-BdxQlNmDT5z8TjqDJZDTuYpzZn8P_4fLGrJwo6crSGO-C1vZ_lH5ZNHvX_bs0lQIEv4ewCFuI8/s1600/CustomReturnType_2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="127" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1XL_f3NcrQIFOXLzxUcKYHa6sHIkvp04uk9Fj9SAyRk4m2ewO_78V8_XylIk3YRWI-BdxQlNmDT5z8TjqDJZDTuYpzZn8P_4fLGrJwo6crSGO-C1vZ_lH5ZNHvX_bs0lQIEv4ewCFuI8/s400/CustomReturnType_2.png" width="400" /></a></div>
<div class="MsoNormal">
In same way we can invoke InternalServerErrorResult.</div>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none; text-indent: .5in;">
<span style="font-family: Consolas; font-size: 9.5pt;">[System.Web.Http.</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HttpGet</span><span style="font-family: Consolas; font-size: 9.5pt;">]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">IHttpActionResult</span><span style="font-family: Consolas; font-size: 9.5pt;"> InternalError()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">InternalServerErrorResult</span><span style="font-family: Consolas; font-size: 9.5pt;">(Request, </span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"My Custom
Error message"</span><span style="font-family: Consolas; font-size: 9.5pt;">); </span><span style="font-family: Consolas; font-size: 9.5pt; text-align: center;"> </span><span style="font-family: Consolas; font-size: 9.5pt; text-align: center;">}</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt; text-align: center;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUqw5sBbaY76h7YTpxHpv-iJbrS6fdBsQPQEGxouSk7FxCv7iSHHdLvh2DhNq_Hvvh1Cj4N8gooAwa1G-BW-eA3jMm-SOFlfT9hEwltO_vD4_pDa3PraxHP7uLL7q-V-Selj7B7Mc3nfQ/s1600/CustomReturnType_3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="146" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUqw5sBbaY76h7YTpxHpv-iJbrS6fdBsQPQEGxouSk7FxCv7iSHHdLvh2DhNq_Hvvh1Cj4N8gooAwa1G-BW-eA3jMm-SOFlfT9hEwltO_vD4_pDa3PraxHP7uLL7q-V-Selj7B7Mc3nfQ/s400/CustomReturnType_3.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="MsoNormal">
<b>Conclusion:</b><span style="font-family: Calibri, sans-serif; font-size: 11pt; text-align: center;">Custom response type is really helpful when you
want to override default behavior of frameworks return type.</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt; text-align: center;"><br /></span></div>
<div class="MsoNormal">
<br /></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0tag:blogger.com,1999:blog-5565818621935638643.post-43222269350304107222016-10-29T08:45:00.000-07:002016-10-29T08:45:16.405-07:00Custom formatter and data binding in MVC<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The purpose of the article is to overcome such scenario where we want
to handle custom data binding in MVC application.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">We know that data binding and Request/Response processing is one of
the key extensible point of MVC framework.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif; font-size: large;"><b>Custom Formatter</b></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Let’s start with custom formatter. This is very useful when we want
to send/get data structure other than JSON or XML. We know that MVC supports
both data encoding scheme by default. <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Probably the other solution to
red off the problem is just to prepare XML or JSON format of your data before
send to API.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">But the better solution could be writing your custom formatter and
hook up in MVC framework.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Say, we have some comma separated information which we want to feed
to API. In this example we will see how to process such value using custom
formatter.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Here is our simplest DTO class.<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;"> public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> Name { </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">get</span><span style="font-family: Consolas; font-size: 9.5pt;">; </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">set</span><span style="font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> Surname { </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">get</span><span style="font-family: Consolas; font-size: 9.5pt;">; </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">set</span><span style="font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }</span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="font-size: 9.5pt;">N</span>ow,
we have created CommaFormatter which is derived from “BufferedMediaTypeFormatter”.
The mime type is chosen in constructor.</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">CommaFormatter</span><span style="font-family: Consolas; font-size: 9.5pt;"> : </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">BufferedMediaTypeFormatter</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> CommaFormatter()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> SupportedMediaTypes.Add(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">MediaTypeHeaderValue</span><span style="font-family: Consolas; font-size: 9.5pt;">(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"application/colon"</span><span style="font-family: Consolas; font-size: 9.5pt;">));<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">override</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">bool</span><span style="font-family: Consolas; font-size: 9.5pt;"> CanReadType(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Type</span><span style="font-family: Consolas; font-size: 9.5pt;"> type)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">if</span><span style="font-family: Consolas; font-size: 9.5pt;"> (type == </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">typeof</span><span style="font-family: Consolas; font-size: 9.5pt;">(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;">) || type == </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">typeof</span><span style="font-family: Consolas; font-size: 9.5pt;">(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">List</span><span style="font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;">>))<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">true</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">else</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">false</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">override</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">bool</span><span style="font-family: Consolas; font-size: 9.5pt;"> CanWriteType(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Type</span><span style="font-family: Consolas; font-size: 9.5pt;"> type)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">if</span><span style="font-family: Consolas; font-size: 9.5pt;"> (type == </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">typeof</span><span style="font-family: Consolas; font-size: 9.5pt;">(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;">) || type == </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">typeof</span><span style="font-family: Consolas; font-size: 9.5pt;">(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">List</span><span style="font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;">>))<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">true</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">else</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">false</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">override</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">object</span><span style="font-family: Consolas; font-size: 9.5pt;"> ReadFromStream(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Type</span><span style="font-family: Consolas; font-size: 9.5pt;"> type, </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Stream</span><span style="font-family: Consolas; font-size: 9.5pt;"> readStream, </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HttpContent</span><span style="font-family: Consolas; font-size: 9.5pt;"> content, </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">IFormatterLogger</span><span style="font-family: Consolas; font-size: 9.5pt;"> formatterLogger)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">List</span><span style="font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;">> Obj = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">List</span><span style="font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;">>();<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;"> p = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">null</span><span style="font-family: Consolas; font-size: 9.5pt;">;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">StreamReader</span><span style="font-family: Consolas; font-size: 9.5pt;"> reader = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">StreamReader</span><span style="font-family: Consolas; font-size: 9.5pt;">(readStream);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> str = reader.ReadToEnd();<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> []propArr = str.Split(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">','</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">foreach</span><span style="font-family: Consolas; font-size: 9.5pt;"> (</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">var</span><span style="font-family: Consolas; font-size: 9.5pt;"> item </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">in</span><span style="font-family: Consolas; font-size: 9.5pt;"> propArr)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;">[] propAttribute = item.Split(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">'|'</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> p = </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">foreach</span><span style="font-family: Consolas; font-size: 9.5pt;"> (</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">var</span><span style="font-family: Consolas; font-size: 9.5pt;"> item1 </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">in</span><span style="font-family: Consolas; font-size: 9.5pt;"> propAttribute)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;">[] propAttribute1 =
item1.Split(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">'='</span><span style="font-family: Consolas; font-size: 9.5pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">if</span><span style="font-family: Consolas; font-size: 9.5pt;">
(propAttribute1[0].ToLower().Trim().Equals(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"name"</span><span style="font-family: Consolas; font-size: 9.5pt;">))<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> p.Name =
propAttribute1[1];<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">if</span><span style="font-family: Consolas; font-size: 9.5pt;">
(propAttribute1[0].ToLower().Trim().Equals(</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"surname"</span><span style="font-family: Consolas; font-size: 9.5pt;">))<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> p.Surname = propAttribute1[1];<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> Obj.Add(p);<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> Obj;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
</div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Now,It’s time to hook up the formatter in Global page ,so that it got
register in MVC.</span><span style="font-family: Consolas;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas;"><br /></span></div>
<div class="MsoNormal">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; line-height: 107%;">GlobalConfiguration</span><span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;">.Configuration.Formatters.Add(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%;">new</span><span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;">
CommaFormatter());<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">In Post method of API we are trying to pass list of “Person”</span><span style="font-family: Consolas;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">CustomController</span><span style="font-family: Consolas; font-size: 9.5pt;"> : </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">ApiController</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
[</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">HttpPost</span><span style="font-family: Consolas; font-size: 9.5pt;">]<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">void</span><span style="font-family: Consolas; font-size: 9.5pt;"> Post(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">List</span><span style="font-family: Consolas; font-size: 9.5pt;"><</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;">> p)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
</div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Please make sure that the “Content-Type” is set in
request header.</span></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgY7Y3O4Nqo_8OjlpmvGYLmE2huWr28mkOhoIQNSZ3CVt3K_EJdF-qo_0ANRwpbCQ9qMoSaG4uWUVDGoI26-d0Oi3K0Hj4AjX3vcbmx5Dii_4S-KosQ_ON-xL3TChaxTowHivzxaByljbM/s1600/CustomFormatter.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="228" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgY7Y3O4Nqo_8OjlpmvGYLmE2huWr28mkOhoIQNSZ3CVt3K_EJdF-qo_0ANRwpbCQ9qMoSaG4uWUVDGoI26-d0Oi3K0Hj4AjX3vcbmx5Dii_4S-KosQ_ON-xL3TChaxTowHivzxaByljbM/s400/CustomFormatter.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">You can observer that the payload is as per our custom data
format.</span><o:p></o:p></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGOviDvs_iKcIX70BUQyqhV9LZxvNFVKcCD6tcuQexkI20C1Hv1F_3jm4JOAKcbFrqn7jDFKjdUhsLosrcK1_9A0dmdCYsiJ2ynxLNsw9Qg7upCB_zqDA-PcFVdGI2r_whHKr3uDnKPeU/s1600/CustomFormatter1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="165" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGOviDvs_iKcIX70BUQyqhV9LZxvNFVKcCD6tcuQexkI20C1Hv1F_3jm4JOAKcbFrqn7jDFKjdUhsLosrcK1_9A0dmdCYsiJ2ynxLNsw9Qg7upCB_zqDA-PcFVdGI2r_whHKr3uDnKPeU/s400/CustomFormatter1.jpg" width="400" /></a></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">And it’s banded to action method.</span><o:p></o:p></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"></span></div>
<div class="MsoNormal">
<b><span style="line-height: 107%;"><span style="font-size: large;">Custom model binding</span><span style="font-size: 14pt;"><o:p></o:p></span></span></b></div>
<div class="MsoNormal">
<b><span style="font-size: 14.0pt; line-height: 107%;"><br /></span></b></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">This is another way to bind unformatted fata to MVC
endpoint. Just think one scenario where data is coming from query string. We
know, that if key of query string matches with model property then MVC is
intelligent enough to bind by default. But what if the query string does not
match with model property?<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The custom model binding comes into picture. We took simple
Person model to demonstrate the example.</span><o:p></o:p></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;"> public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> Name { </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">get</span><span style="font-family: Consolas; font-size: 9.5pt;">; </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">set</span><span style="font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> Surname { </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">get</span><span style="font-family: Consolas; font-size: 9.5pt;">; </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">set</span><span style="font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="font-size: 14.0pt; line-height: 107%;"><br /></span></b></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Now, here we have created PersonModelBinder which is derived
from DefaultModelBinder and override BindModel method.<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">In this method we are getting value of query string from
request context and returning as concrete object of person model.</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></span></div>
<div class="MsoNormal">
<b><span style="font-size: 14.0pt; line-height: 107%;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">PersonModelBinder</span><span style="font-family: Consolas; font-size: 9.5pt;"> : </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">DefaultModelBinder</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{ <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> PersonModelBinder()<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<br /></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">override</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">object</span><span style="font-family: Consolas; font-size: 9.5pt;"> BindModel(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">ControllerContext</span><span style="font-family: Consolas; font-size: 9.5pt;"> controllerContext, </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">ModelBindingContext</span><span style="font-family: Consolas; font-size: 9.5pt;"> bindingContext)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">var</span><span style="font-family: Consolas; font-size: 9.5pt;"> request =
controllerContext.HttpContext.Request;<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> name = request.QueryString[</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"name"</span><span style="font-family: Consolas; font-size: 9.5pt;">];<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">string</span><span style="font-family: Consolas; font-size: 9.5pt;"> surname = request.QueryString[</span><span style="color: #a31515; font-family: Consolas; font-size: 9.5pt;">"surname"</span><span style="font-family: Consolas; font-size: 9.5pt;">];<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">return</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">new</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;"> { Name = name, Surname = surname };<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Here is the procedure to hook up the custom formatter in
MVC pipeline.</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"></span></div>
<div class="MsoNormal">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; line-height: 107%;">ModelBinders</span><span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;">.Binders.Add(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%;">typeof</span><span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;">(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; line-height: 107%;">Person</span><span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;">), </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 107%;">new</span><span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt; line-height: 107%;">PersonModelBinder</span><span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;">());<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">To receive data as parameter we have to use
ModelBinder attribute</span></span></div>
<div class="MsoNormal">
<b><span style="font-size: 14.0pt; line-height: 107%;"><br /></span></b></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">class</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">CustomController</span><span style="font-family: Consolas; font-size: 9.5pt;"> : </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Controller</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">void</span><span style="font-family: Consolas; font-size: 9.5pt;"> Post([</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">ModelBinder</span><span style="font-family: Consolas; font-size: 9.5pt;">(</span><span style="color: blue; font-family: Consolas; font-size: 9.5pt;">typeof</span><span style="font-family: Consolas; font-size: 9.5pt;">(</span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">PersonModelBinder</span><span style="font-family: Consolas; font-size: 9.5pt;">))] </span><span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">Person</span><span style="font-family: Consolas; font-size: 9.5pt;"> p)<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Consolas; font-size: 9.5pt;">
}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 9.5pt; line-height: 107%;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
</div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">We are seeing that the value
is binded in action.</span><o:p></o:p></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_z1yp-NHIv7qXa7sDh00hrVWY1vBNGnaCFW_ofbxJ47K1MI0c-pdDMDdeIvKZ9maO-EeW5cnNOc4um_POVI8EbHAoJJep0b4MJ2VJpPg73X5lOh6N3wttOPTrr9Zn9MyV4l8wutGlLTk/s1600/CustomFormatter2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="102" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_z1yp-NHIv7qXa7sDh00hrVWY1vBNGnaCFW_ofbxJ47K1MI0c-pdDMDdeIvKZ9maO-EeW5cnNOc4um_POVI8EbHAoJJep0b4MJ2VJpPg73X5lOh6N3wttOPTrr9Zn9MyV4l8wutGlLTk/s400/CustomFormatter2.jpg" width="400" /></a></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Conclusion: In this two example we have seen how to handle
custom data format in MVC. The formatter is useful when you don’t want to
convert your data to XML or JSON prior to send to API and custom model binder
is suitable when the amount of data is small and short enough to pass as query
string.</span><o:p></o:p></div>
<div class="MsoNormal">
<b><span style="font-size: 14.0pt; line-height: 107%;"><br /></span></b></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0tag:blogger.com,1999:blog-5565818621935638643.post-60197341250976985632016-10-29T08:24:00.002-07:002016-10-29T08:24:35.554-07:00Web Activator<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Web Activator is useful if you want to hook up your code before
to or end of application execution. Logging before and after execution of
application might be one scenario where we can use Web Activator.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">To use Web Activator we have to get it from
NuGet. Just install this package.</span></span><br />
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDDHp6s6LYDUrjgJtuS6Hid2OewuViHvJp0dpFaFc-GMHIbFPks4crVBmfGVvYtKNBF5AjojzMRn-l1cHOdTYbVhZGR9Hl0bnAuKaIfsnFN9aOa4bxMcSs7XowNDkYWy6900nizRj9x8k/s1600/Nuget+Web+Activator.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="162" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDDHp6s6LYDUrjgJtuS6Hid2OewuViHvJp0dpFaFc-GMHIbFPks4crVBmfGVvYtKNBF5AjojzMRn-l1cHOdTYbVhZGR9Hl0bnAuKaIfsnFN9aOa4bxMcSs7XowNDkYWy6900nizRj9x8k/s400/Nuget+Web+Activator.jpg" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Web Activator has 4 flavor to hook custom code in place. In
this example we have used PreApplicationStartMethod <o:p></o:p></span></div>
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaQOZ4Yisiyod6RdmUHO8Ayz_Nhh1PjmKkq8fi11wwS8KI1p9-B1NpdgK_OVEznafkDkIZdGj7x-z-E5hXLQ_gNU3XB4Gh3WJoAS3J7GxaVRaiQcmX3Gv8swyS6XrsGJ8hyphenhyphenD9yfChRtps/s1600/Nuget+Web+Activator1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><img border="0" height="147" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaQOZ4Yisiyod6RdmUHO8Ayz_Nhh1PjmKkq8fi11wwS8KI1p9-B1NpdgK_OVEznafkDkIZdGj7x-z-E5hXLQ_gNU3XB4Gh3WJoAS3J7GxaVRaiQcmX3Gv8swyS6XrsGJ8hyphenhyphenD9yfChRtps/s400/Nuget+Web+Activator1.jpg" width="400" /></span></a></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">For demonstration. So, the method will execute before
anything executes in application. Yes, before Application_Start or execution of
App_Code folder’s code. Here is way to hook up code using Web Activator.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="font-size: 9.5pt;">[</span><span style="color: blue; font-size: 9.5pt;">assembly</span><span style="font-size: 9.5pt;"> : WebActivatorEx.</span><span style="color: #2b91af; font-size: 9.5pt;">PreApplicationStartMethod</span><span style="font-size: 9.5pt;">(</span><span style="color: blue; font-size: 9.5pt;">typeof</span><span style="font-size: 9.5pt;">(Mvc.Models.</span><span style="color: #2b91af; font-size: 9.5pt;">FirstClass</span><span style="font-size: 9.5pt;">),</span><span style="color: #a31515; font-size: 9.5pt;">"FirstMethod"</span><span style="font-size: 9.5pt;">)]<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="color: blue; font-size: 9.5pt;">namespace</span><span style="font-size: 9.5pt;"> Mvc.Models<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-size: 9.5pt;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="font-size: 9.5pt;">
</span><span style="color: blue; font-size: 9.5pt;">public</span><span style="font-size: 9.5pt;"> </span><span style="color: blue; font-size: 9.5pt;">class</span><span style="font-size: 9.5pt;"> </span><span style="color: #2b91af; font-size: 9.5pt;">FirstClass</span><span style="font-size: 9.5pt;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-size: 9.5pt;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><span style="font-size: 9.5pt;">
</span><span style="color: blue; font-size: 9.5pt;">public</span><span style="font-size: 9.5pt;"> </span><span style="color: blue; font-size: 9.5pt;">static</span><span style="font-size: 9.5pt;"> </span><span style="color: blue; font-size: 9.5pt;">void</span><span style="font-size: 9.5pt;"> FirstMethod()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-size: 9.5pt;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-size: 9.5pt;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"> <o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-size: 9.5pt;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="line-height: normal; margin-bottom: .0001pt; margin-bottom: 0in; mso-layout-grid-align: none; text-autospace: none;">
<span style="font-size: 9.5pt;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">
}<o:p></o:p></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoNormal">
<span style="font-size: 9.5pt; line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">}</span></span><o:p></o:p></div>
<span style="line-height: 107%;"><span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span></span></div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0tag:blogger.com,1999:blog-5565818621935638643.post-19850266561440265822016-01-15T19:42:00.000-08:002016-01-15T19:42:21.332-08:00Understand Run, Use, Map and MapWhen to Hook Middleware in HTTP Pipeline of ASP.NET5<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="background-color: white; color: #ff9900; font-weight: 200; margin: 20px 0px 11px; padding: 0px 0px 10px;">
<span style="color: #111111;"><span style="font-family: Trebuchet MS, sans-serif; font-size: small;">It’s more transparent to hook middleware in ASP.NET 5 application compared to prior versions. We can use Run, Map and Use extension method to hook any middleware in between HTTP pipeline. In this example, we will understand the difference among them with an example.</span></span></h2>
<div>
<span style="color: #111111;"><span style="font-family: Trebuchet MS, sans-serif; font-size: small;">Read Full article here...</span></span></div>
<div>
<span style="color: #111111;"><span style="font-family: Trebuchet MS, sans-serif; font-size: small;"><br /></span></span></div>
<div>
<span style="color: #111111; font-family: Trebuchet MS, sans-serif;"><a href="http://www.codeproject.com/Tips/1069790/Understand-Run-Use-Map-and-MapWhen-to-Hook-Middl">http://www.codeproject.com/Tips/1069790/Understand-Run-Use-Map-and-MapWhen-to-Hook-Middl</a></span></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0tag:blogger.com,1999:blog-5565818621935638643.post-84125424536482364982016-01-15T19:40:00.000-08:002016-01-15T19:40:11.165-08:00Understanding Startup.cs file in ASP.NET 5<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="background-color: white; color: #ff9900; font-weight: 200; margin: 20px 0px 11px; padding: 0px 0px 10px;">
<span style="font-family: Trebuchet MS, sans-serif; font-size: small;"><em style="border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: #111111; margin: 0px; padding: 0px;">Startup.cs</em><span style="color: #111111;"> </span><span style="color: #111111;">file is a replacement of</span><span style="color: #111111;"> </span><em style="border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: #111111; margin: 0px; padding: 0px;">Global.asax</em><span style="color: #111111;"> </span><span style="color: #111111;">file in ASP.NET Web Form application. We know that</span><span style="color: #111111;"> </span><em style="border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: #111111; margin: 0px; padding: 0px;">Global.asax</em><span style="color: #111111;"> </span><span style="color: #111111;">is an optional file to handle Application level event in ASP.NET application. In ASP.NET 5,</span><span style="color: #111111;"> </span><em style="border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: #111111; margin: 0px; padding: 0px;">Startup.cs</em><span style="color: #111111;"> </span><span style="color: #111111;">file has introduce to server same.</span></span></h2>
<div>
<span style="font-family: Trebuchet MS, sans-serif; font-size: small;"><span style="color: #111111;">Read Full article here..</span></span></div>
<div>
<span style="color: #111111; font-family: Trebuchet MS, sans-serif;"><a href="http://www.codeproject.com/Tips/1069787/Understanding-Startup-cs-file-in-ASP-NET">http://www.codeproject.com/Tips/1069787/Understanding-Startup-cs-file-in-ASP-NET</a></span></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0tag:blogger.com,1999:blog-5565818621935638643.post-65600035948849555942016-01-15T19:37:00.000-08:002016-01-15T19:37:07.346-08:00Working with Service in ASP.NET 5 Application<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Trebuchet MS, sans-serif; font-size: large;">Recently I have published one article in codeproject regarding working with services in ASP.NET 5 . Please read full article here.</span><br />
<br />
<h1 id="ctl00_ArticleTitle" itemprop="name" style="background-color: white; margin: 0px 0px 15px; padding: 0px;">
<span style="color: #333333; font-family: Segoe UI, Arial, sans-serif;"><span style="font-size: 29px; font-weight: 200;"><a href="http://www.codeproject.com/Articles/1070986/Working-with-Service-in-ASP-NET-Application" target="_blank">http://www.codeproject.com/Articles/1070986/Working-with-Service-in-ASP-NET-Application</a></span></span></h1>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0tag:blogger.com,1999:blog-5565818621935638643.post-30534960654924021032015-12-20T19:23:00.000-08:002015-12-20T19:23:22.612-08:00Action injection in MVC6<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-size: large;">Dependency injection is very flexible in MVC6 architecture.
Now, it’s possible to inject dependency only in action level.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: large;">Earlier, if there was need to inject dependency then there
were three possible ways <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: large;">1) Constructor injection<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: large;">2) Function injection <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: large;">3) Property injection<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: large;">Now, the common part of these technique is, it will resolve
dependency in class level. So, if there is need to resolve dependency only in
one function those techniques are not best fit.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: large;">In MVC6 Microsoft has introduce injection in function level.
Just we need to use [FromService] </span></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: large;">attribute in parameter and it will resolve
dependency from IoC container.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: large;">Let’s implement small example to understand the same. Here
is implementation of Message service.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas;"><span style="font-size: large;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; color: blue; font-family: Consolas;"> public</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">interface</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: #2b91af; font-family: Consolas;">IMessage</span><span style="background: white; font-family: Consolas;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">string</span><span style="background: white; font-family: Consolas;"> Message { </span><span style="background: white; color: blue; font-family: Consolas;">get</span><span style="background: white; font-family: Consolas;">; </span><span style="background: white; color: blue; font-family: Consolas;">set</span><span style="background: white; font-family: Consolas;">; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">public</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">class</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: #2b91af; font-family: Consolas;">Message</span><span style="background: white; font-family: Consolas;"> : </span><span style="background: white; color: #2b91af; font-family: Consolas;">IMessage</span><span style="background: white; font-family: Consolas;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">string</span><span style="background: white; font-family: Consolas;"> _message;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">string</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: #2b91af; font-family: Consolas;">IMessage</span><span style="background: white; font-family: Consolas;">.Message<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">get</span><span style="background: white; font-family: Consolas;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> _message = </span><span style="background: white; color: #a31515; font-family: Consolas;">"System message"</span><span style="background: white; font-family: Consolas;">;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">return</span><span style="background: white; font-family: Consolas;"> _message;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">set</span><span style="background: white; font-family: Consolas;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> _message = </span><span style="background: white; color: blue; font-family: Consolas;">value</span><span style="background: white; font-family: Consolas;">;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><span style="background: white; font-family: Consolas; line-height: 107%;"> }</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: large;">Message class has implemented IMessage interface. Now, we
have to register those in IoC container of MVC6. I am using default IoC
container in this example. <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas;"><span style="font-size: large;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; color: blue; font-family: Consolas;">public</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">void</span><span style="background: white; font-family: Consolas;"> ConfigureServices(</span><span style="background: white; color: #2b91af; font-family: Consolas;">IServiceCollection</span><span style="background: white; font-family: Consolas;"> services)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> services.AddTransient<</span><span style="background: white; color: #2b91af; font-family: Consolas;">IMessage</span><span style="background: white; font-family: Consolas;">, </span><span style="background: white; color: #2b91af; font-family: Consolas;">Message</span><span style="background: white; font-family: Consolas;">>();<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><span style="background: white; font-family: Consolas; line-height: 107%;"> }</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: large;">All done, now we are allowed to resolve dependency from action
using “FromService” attribute.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas;"><span style="font-size: large;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; color: blue; font-family: Consolas;">public</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: #2b91af; font-family: Consolas;">IActionResult</span><span style="background: white; font-family: Consolas;"> Index([</span><span style="background: white; color: #2b91af; font-family: Consolas;">FromServices</span><span style="background: white; font-family: Consolas;">] </span><span style="background: white; color: #2b91af; font-family: Consolas;">IMessage</span><span style="background: white; font-family: Consolas;"> Today)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">string</span><span style="background: white; font-family: Consolas;"> message = Today.Message;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">return</span><span style="background: white; font-family: Consolas;"> View();<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal">
<span style="font-size: large;"><span style="background: white; font-family: Consolas; line-height: 107%;"> }</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background: white; font-family: Consolas; line-height: 107%;"><span style="font-size: large;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdfwOlUYGcgGslglcRhxpvKGr85ym5kv47imqi0XAeQ46I_7lqsqQeEeDnSD4Rt_ieIF89marTr-jemzgAyo-cUWOZEEaGZL6IgNk6OSLg_0v9YFSCM14bpRmH_gRM0n9_ob_j9jBFrPc/s1600/Action+injection+ctrlcvprogrammer.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-size: large;"><img border="0" height="125" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdfwOlUYGcgGslglcRhxpvKGr85ym5kv47imqi0XAeQ46I_7lqsqQeEeDnSD4Rt_ieIF89marTr-jemzgAyo-cUWOZEEaGZL6IgNk6OSLg_0v9YFSCM14bpRmH_gRM0n9_ob_j9jBFrPc/s400/Action+injection+ctrlcvprogrammer.jpg" width="400" /></span></a></div>
<div class="MsoNormal">
<span style="background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com1tag:blogger.com,1999:blog-5565818621935638643.post-76457211615391946952015-12-18T09:21:00.000-08:002015-12-18T09:21:23.487-08:00Another story of a great mother.<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqE5iPSNifZNIw34RrUgwQD_UFKvEZUptJ7jM7KNDrPxjpkfN_cjH1Vc1LOaJPuGRyoCQdx0fp-WB6PQeoamj9L-pBpirXz7SJSDWPjcp2gsf1vtugD5FvLOxLj_-deulNcgj-AmHSCk0/s1600/mothers+sacrifice.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqE5iPSNifZNIw34RrUgwQD_UFKvEZUptJ7jM7KNDrPxjpkfN_cjH1Vc1LOaJPuGRyoCQdx0fp-WB6PQeoamj9L-pBpirXz7SJSDWPjcp2gsf1vtugD5FvLOxLj_-deulNcgj-AmHSCk0/s1600/mothers+sacrifice.jpg" /></a></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Few days ago I have been in my hometown, went as routine
visit from my workplace. Time is really fast when you spent it with your
dearest person. I could not even imagine how 10 days passed just like 10
minutes.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Anyway, one evening my mom told that she has one marriage
invitation from our neighbor village on this evening and started preparation to
attend.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">When she came back from marriage ceremony I was watching TV
by sitting on sofa. I casually asked, whose marriage it was? Mom replied, it is
the marriage of her friend’s house (I personally don’t know her but hear her
name many times in time of conversation with mother). Mon started to tell how
she became mate with her and why she respect and value to my mom!<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">It’s been very early when her husband passed away by leaving
few kids along with her. She has no Idea to manage her and sons life. She took maid’s
job and started to earn their living which was not really sufficient. Just to
secure food for same day, she accepted hard work in a brick factory where
physically strong people normally deny to work due to heavy labor.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">In spite of being illiterate, she has great desire that her
son will get good education. It seems that education is nothing but there day dream.
<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">She decided, “I don’t have enough resource to educate all of
my children but can educate one among them”. Now, the question is, to whom to choose?
She found that, the youngest one has
real interest in education. She send him in a nearest Government school. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Situation became worst, now a large part of earning started
to go behind his education (though government school is free, but there is
expenditure of private tuition and education materials). To collect additional
money she started begging door to door. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"> Once she came to our house too. My mother
asked, why she is begging (casually! just to know the reason). She replied, she
wish “AT LEAST ONE OF HER SON WILL BE EDUCATED” and for sake of it, she started
begging.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">My mother got surprised
(me too! when, I hear from my mother). Mother gave few books (English grammar etc.,
as my father is teacher of English subject and used to get book in free as specimen
copy) copy/note of mine and get her promise that “In any situation , she will
not stop her son’s education”. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">She said Didi ! (Elder sister in Bengali, she used to call
my mom like this) I faced that day, when alms is not enough for all family
member, I distributed rice of my part among my children and drunk water at night.
If I can handle this situation, I can handle any situation. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">What is great sacrifice! Yes, she kept her promise, she
never stopped her son’s education. Today her son became teacher of a government
school and and and…? Yes, my mother just return by attending his marriage.<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">I asked, how the bride looks like. Replied: very nice... hahhah... </span><o:p></o:p></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com3tag:blogger.com,1999:blog-5565818621935638643.post-63827722158157638742015-12-18T00:28:00.001-08:002015-12-18T00:29:29.179-08:00Inject service to View in MVC6<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">This is new feature of MVC6, you can inject service to view
directly. It will help to push/pull data from UI to business logic directly by
skipping controller layer.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Here, we will implement small example to demonstrate the
concept. <o:p></o:p></span></div>
<div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> </span></div>
<div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> <b>1)<span style="font-stretch: normal;">
</span><!--[endif]-->At first we will create one simple service like
this.</b><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white; color: blue;">namespace</span><span style="background: white;"> MVC6Web.Services<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">class</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">Person</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">int</span><span style="background: white;"> Id { </span><span style="background: white; color: blue;">get</span><span style="background: white;">; </span><span style="background: white; color: blue;">set</span><span style="background: white;">; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">string</span><span style="background: white;"> Name { </span><span style="background: white; color: blue;">get</span><span style="background: white;">; </span><span style="background: white; color: blue;">set</span><span style="background: white;">; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">class</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">DataService</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: #2b91af;">Person</span><span style="background: white;"> _person;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> DataService()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white;"> _person = </span><span style="background: white; color: blue;">new</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">Person</span><span style="background: white;"> { </span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white;"> Id = 1, Name = </span><span style="background: white; color: #a31515;">"Sourav Kayal"</span><span style="background: white;">
};<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">Person</span><span style="background: white;"> GetPerson()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">return</span><span style="background: white;"> _person;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">}<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">DataService is simple C# class containing GetPerson()
function which will return an object of Person class.<o:p></o:p></span></div>
<div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> </span></div>
<div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> <b> 2)<span style="font-stretch: normal;">
</span><!--[endif]-->Make the service visible to MVC environment.</b><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> In this point we will
attach DataService to environment of current project. So, modify the
ConfigureService function like below.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">void</span><span style="background: white;"> ConfigureServices(</span><span style="background: white; color: #2b91af;">IServiceCollection</span><span style="background: white;"> services)<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white; line-height: 107%;">{</span><span style="line-height: 107%;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="text-indent: .5in;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white; line-height: 107%;">services.AddTransient<MVC6Web.Services.</span><span style="background: white; color: #2b91af; line-height: 107%;">DataService</span><span style="background: white; line-height: 107%;">>();</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="line-height: 107%;"><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">}<o:p></o:p></span></span></div>
<div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> </span></div>
<div class="MsoListParagraph" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> <b>3)<span style="font-stretch: normal;">
</span><!--[endif]-->Inject DataService to view.</b><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">This is the final step, here we will inject the service to
view. Here is the procedure to get it done.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: yellow;">@inject
</span><span style="background: white;">MVC6Web.Services.DataService
DataService <o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white; color: blue;"><</span><span style="background: white; color: maroon;">ul</span><span style="background: white; color: blue;">></span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;"><</span><span style="background: white; color: maroon;">li</span><span style="background: white; color: blue;">></span><span style="background: white;">Item : </span><span style="background: yellow;">@</span><span style="background: white;">DataService.GetPerson().Name</span><span style="background: white; color: blue;"></</span><span style="background: white; color: maroon;">li</span><span style="background: white; color: blue;">></span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><span style="background: white; color: blue;"></</span><span style="background: white; color: maroon;">ul</span><span style="background: white; color: blue;">></span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">The format to inject to Service is like this.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">@inject <ServicePath> <Identifier><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;">Once we inject service, we are allowed to call GetPerson()
function from view itself, though the function is not part of controller.<o:p></o:p></span></div>
<span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p><span style="font-family: "arial" , "helvetica" , sans-serif; font-size: large;"> </span></o:p><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1wM2w9-SC_wfjv6Fxe-3Rcs_9tAl5VbB_qUz7O4CRqvFM5Nq0GIsJQSnq2-wjwo5jFrpnQ1s5IaZpEIQNJYzI8XfhYgqQrTqBOTciSKPoPAo0vDUdL_0JG4b2l4PbZryd1eLN2ftQbMY/s1600/Sourav+kayal_Inject+service+to+view.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="116" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1wM2w9-SC_wfjv6Fxe-3Rcs_9tAl5VbB_qUz7O4CRqvFM5Nq0GIsJQSnq2-wjwo5jFrpnQ1s5IaZpEIQNJYzI8XfhYgqQrTqBOTciSKPoPAo0vDUdL_0JG4b2l4PbZryd1eLN2ftQbMY/s400/Sourav+kayal_Inject+service+to+view.jpg" width="400" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0tag:blogger.com,1999:blog-5565818621935638643.post-1295912802779796662015-11-28T03:48:00.000-08:002015-11-28T03:48:26.536-08:00Struggling with Node package installation behind proxy?<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-size: large;">Recently Microsoft has released kit for node.js application
development on top of Visual Studio. I have been exploring this from last few
days. I was getting proxy related error which is something like this<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDCeqBoSoEZ0ad8bEp9udSpBeQ3RoIWU065EXdjQDy4tft2sEn86rhPCDHtsvtPK5rh96Bu4i3tJh0i3EWy-AFJZHAXWwiHr0qUl3XYtagYq_Z_8gpxkQ_rzGNudO94HlslnfiGC0AiYU/s1600/NPM_proxy+error.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-size: large;"><img alt="NodeJS ETIMEOUT ERROR" border="0" height="105" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDCeqBoSoEZ0ad8bEp9udSpBeQ3RoIWU065EXdjQDy4tft2sEn86rhPCDHtsvtPK5rh96Bu4i3tJh0i3EWy-AFJZHAXWwiHr0qUl3XYtagYq_Z_8gpxkQ_rzGNudO94HlslnfiGC0AiYU/s640/NPM_proxy+error.jpg" title="NodeJS ETIMEOUT ERROR" width="640" /></span></a></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: large;">In time of package installation of node. It was saying that,
as you are behind proxy you cannot install package without setting proper
proxy.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: large;">Anyway, I spent a single day with every possible solution
from stack overflow and other site too by configuring node configuration file
as per there suggestion but no luck.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: large;">At last, I found one answer in stack overflow( Which was not
marked as answer though ! ) which suggesting to delete the proxy setting and
the command is here.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="color: red;"><span style="font-size: large;"><br /></span></span></b></div>
<div class="MsoNormal">
<b><span style="color: red;"><span style="font-size: large;"> npm config delete proxy<o:p></o:p></span></span></b></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: large;">Ohhhhhhhhhhhhh…… !!!!!! That works’ for me. After a long
search I could able to solve the issue. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Calibri, sans-serif; line-height: 107%;"><span style="font-size: large;"> </span></span></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com1tag:blogger.com,1999:blog-5565818621935638643.post-21253216784827153992015-11-21T23:57:00.000-08:002015-11-21T23:57:15.504-08:00Populate real time data for testing using GenFu API C#<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-size: large;">We need test data very often for sake of testing in Test or
UAT server. There are Few API’s available which can generate random data.
Fixture and AutoFixture is such kind of library but the limitation is, It will
generates random string. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: large;">The beauty of GenFu is, it will provide you real time value.
Here is one example.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas;"><span style="font-size: large;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; color: blue; font-family: Consolas;">public</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">class</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: #2b91af; font-family: Consolas;">Contact</span><span style="background: white; font-family: Consolas;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">public</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">int</span><span style="background: white; font-family: Consolas;"> Id { </span><span style="background: white; color: blue; font-family: Consolas;">get</span><span style="background: white; font-family: Consolas;">; </span><span style="background: white; color: blue; font-family: Consolas;">set</span><span style="background: white; font-family: Consolas;">; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">public</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">string</span><span style="background: white; font-family: Consolas;"> FirstName { </span><span style="background: white; color: blue; font-family: Consolas;">get</span><span style="background: white; font-family: Consolas;">; </span><span style="background: white; color: blue; font-family: Consolas;">set</span><span style="background: white; font-family: Consolas;">; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">public</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">string</span><span style="background: white; font-family: Consolas;"> LastName { </span><span style="background: white; color: blue; font-family: Consolas;">get</span><span style="background: white; font-family: Consolas;">; </span><span style="background: white; color: blue; font-family: Consolas;">set</span><span style="background: white; font-family: Consolas;">; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">public</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">string</span><span style="background: white; font-family: Consolas;"> EmailAdress { </span><span style="background: white; color: blue; font-family: Consolas;">get</span><span style="background: white; font-family: Consolas;">; </span><span style="background: white; color: blue; font-family: Consolas;">set</span><span style="background: white; font-family: Consolas;">; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">public</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">string</span><span style="background: white; font-family: Consolas;"> PhoneNumber { </span><span style="background: white; color: blue; font-family: Consolas;">get</span><span style="background: white; font-family: Consolas;">; </span><span style="background: white; color: blue; font-family: Consolas;">set</span><span style="background: white; font-family: Consolas;">; }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">public</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">override</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">string</span><span style="background: white; font-family: Consolas;"> ToString()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">return</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: #a31515; font-family: Consolas;">$"</span><span style="background: white; font-family: Consolas;">{Id}</span><span style="background: white; color: #a31515; font-family: Consolas;">: </span><span style="background: white; font-family: Consolas;">{FirstName}</span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; color: #a31515; font-family: Consolas;"></span><span style="background: white; font-family: Consolas;"> {LastName}</span><span style="background: white; color: #a31515; font-family: Consolas;"> - </span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> {EmailAdress}</span><span style="background: white; color: #a31515; font-family: Consolas;"> - </span><span style="background: white; font-family: Consolas;">{PhoneNumber}</span><span style="background: white; color: #a31515; font-family: Consolas;">"</span><span style="background: white; font-family: Consolas;">;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><span style="background: white; font-family: Consolas; line-height: 107%;"> }</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: large;">The class definition is very simple and self-explanatory.
Now, we will call API function to Generate random objects for the class.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas;"><span style="font-size: large;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; color: blue; font-family: Consolas;"> public</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">static</span><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">void</span><span style="background: white; font-family: Consolas;"> Main(</span><span style="background: white; color: #2b91af; font-family: Consolas;">String</span><span style="background: white; font-family: Consolas;">[] args)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: green; font-family: Consolas;">//Generate
25 random </span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; color: green; font-family: Consolas;"> //Information by default</span><span style="background: white; font-family: Consolas;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">var</span><span style="background: white; font-family: Consolas;"> people = </span><span style="background: white; color: #2b91af; font-family: Consolas;">A</span><span style="background: white; font-family: Consolas;">.ListOf<</span><span style="background: white; color: #2b91af; font-family: Consolas;">Contact</span><span style="background: white; font-family: Consolas;">>();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: blue; font-family: Consolas;">foreach</span><span style="background: white; font-family: Consolas;"> (</span><span style="background: white; color: blue; font-family: Consolas;">var</span><span style="background: white; font-family: Consolas;"> person </span><span style="background: white; color: blue; font-family: Consolas;">in</span><span style="background: white; font-family: Consolas;"> people)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: #2b91af; font-family: Consolas;">Console</span><span style="background: white; font-family: Consolas;">.</span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> WriteLine(person.ToString());<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; font-family: Consolas;"><span style="font-size: large;">
}<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-size: large;"><span style="background: white; font-family: Consolas;"> </span><span style="background: white; color: #2b91af; font-family: Consolas;">Console</span><span style="background: white; font-family: Consolas;">.ReadLine();<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-size: large;"><span style="background: white; font-family: Consolas; line-height: 107%;"> }</span><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large; margin-left: 1em; margin-right: 1em;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZ0FotCPWhSZNgrzhFUSvySj-ikA0SGLhiS_b-ZMiJ-IDTXuRejLLpflG9vDjioG9wnYQh5e9JzsWpHlObzhbz8WChnJyvSb_PwO0EdovkgruQtaKn4hscX9_Qob2QR533eP2kdLhjI_U/s1600/GenFu+Example+C%2523.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img alt="GenFu to load real time data" border="0" height="162" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZ0FotCPWhSZNgrzhFUSvySj-ikA0SGLhiS_b-ZMiJ-IDTXuRejLLpflG9vDjioG9wnYQh5e9JzsWpHlObzhbz8WChnJyvSb_PwO0EdovkgruQtaKn4hscX9_Qob2QR533eP2kdLhjI_U/s400/GenFu+Example+C%2523.jpg" title="GenFu to load real time data" width="400" /></a></span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="MsoNormal">
<span style="font-size: large;">Please read more about GenFu in below link.</span><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoNormal">
<a href="http://www.davepaquette.com/archive/2015/11/15/realistic-sample-data-with-genfu.aspx">http://www.davepaquette.com/archive/2015/11/15/realistic-sample-data-with-genfu.aspx</a><o:p></o:p></div>
<span style="font-family: Calibri, sans-serif; line-height: 107%;"><span style="font-size: large;"> </span></span></div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com2tag:blogger.com,1999:blog-5565818621935638643.post-67370831340765343532015-11-21T00:06:00.000-08:002015-11-21T00:06:38.002-08:00Avoid multiple If-else Or Switch in decision making flow.<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Sometime multiple if-else or switch can increase code smell.
It’s always Good practice to avoid those to decrease confusion and increase
code readability.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">In this article we will implement some pattern which can
replace simple if-else or switch case. Let’s take one small example to
implement same.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white; color: blue;"> public</span><span style="background: white;"> </span><span style="background: white; color: blue;">interface</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">IMessage</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">void</span><span style="background: white;"> Send();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">class</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">SMS</span><span style="background: white;"> : </span><span style="background: white; color: #2b91af;">IMessage</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">void</span><span style="background: white;"> Send()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> System.</span><span style="background: white; color: #2b91af;">Console</span><span style="background: white;">.WriteLine(</span><span style="background: white; color: #a31515;">"SMS Sending.."</span><span style="background: white;">);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">class</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">Mail</span><span style="background: white;"> : </span><span style="background: white; color: #2b91af;">IMessage</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">void</span><span style="background: white;"> Send()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> System.</span><span style="background: white; color: #2b91af;">Console</span><span style="background: white;">.WriteLine(</span><span style="background: white; color: #a31515;">"Mail Sending.."</span><span style="background: white;">);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white; line-height: 107%;"> }</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">We have implement IMessage in SMS and Mail classes. Now, here
is an Enum to choose the Message type.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background: white; color: blue; line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white; color: blue; line-height: 107%;">enum</span><span style="background: white; line-height: 107%;"> </span><span style="background: white; color: #2b91af; line-height: 107%;">MessageType</span><span style="background: white; line-height: 107%;"> {
Sms, Mail };</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Here is the actual logic to call appropriate class.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white; color: blue;"> public</span><span style="background: white;"> </span><span style="background: white; color: blue;">static</span><span style="background: white;"> </span><span style="background: white; color: blue;">void</span><span style="background: white;"> Main(</span><span style="background: white; color: #2b91af;">String</span><span style="background: white;">[] args)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: #2b91af;">Dictionary</span><span style="background: white;"><</span><span style="background: white; color: #2b91af;">MessageType</span><span style="background: white;">, </span><span style="background: white; color: #2b91af;">IMessage</span><span style="background: white;">> ObjectFactory = <o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 1in; text-indent: 0.5in;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white; color: blue;">new</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">Dictionary</span><span style="background: white;"><</span><span style="background: white; color: #2b91af;">MessageType</span><span style="background: white;">, </span><span style="background: white; color: #2b91af;">IMessage</span><span style="background: white;">><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> { </span><span style="background: white; color: #2b91af;">MessageType</span><span style="background: white;">.Sms, </span><span style="background: white; color: blue;">new</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">SMS</span><span style="background: white;">() },<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> { </span><span style="background: white; color: #2b91af;">MessageType</span><span style="background: white;">.Mail, </span><span style="background: white; color: blue;">new</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">Mail</span><span style="background: white;">() }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> };<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> System.</span><span style="background: white; color: #2b91af;">Console</span><span style="background: white;">.WriteLine(</span><span style="background: white; color: #a31515;">"0: For SMS, 1: Mail"</span><span style="background: white;">);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">int</span><span style="background: white;"> ReadType = </span><span style="background: white; color: #2b91af;">Convert</span><span style="background: white;">.ToInt32(</span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> System.</span><span style="background: white; color: #2b91af;">Console</span><span style="background: white;">.ReadLine());<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> ObjectFactory[(</span><span style="background: white; color: #2b91af;">MessageType</span><span style="background: white;">)ReadType].Send();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> <o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> System.</span><span style="background: white; color: #2b91af;">Console</span><span style="background: white;">.ReadLine();<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white; line-height: 107%;"> }</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">The implementation is very simple one. Just we are maintaining
one dictionary by containing object of concrete implementation of the IMessage
interface.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;">Once user input some value, we are getting appropriate
object and calling respective function. Here is Full code implementation with
output.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white; color: blue;">using</span><span style="background: white;"> System;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white; color: blue;">using</span><span style="background: white;"> System.Collections.Generic;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white; color: blue;">using</span><span style="background: white;"> System.Linq;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white; color: blue;">using</span><span style="background: white;"> System.Text;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white; color: blue;">using</span><span style="background: white;"> System.Threading.Tasks;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white; color: blue;">namespace</span><span style="background: white;"> Console<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">{<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">interface</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">IMessage</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">void</span><span style="background: white;"> Send();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">class</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">SMS</span><span style="background: white;"> : </span><span style="background: white; color: #2b91af;">IMessage</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">void</span><span style="background: white;"> Send()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> System.</span><span style="background: white; color: #2b91af;">Console</span><span style="background: white;">.WriteLine(</span><span style="background: white; color: #a31515;">"SMS Sending.."</span><span style="background: white;">);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">class</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">Mail</span><span style="background: white;"> : </span><span style="background: white; color: #2b91af;">IMessage</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">void</span><span style="background: white;"> Send()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> System.</span><span style="background: white; color: #2b91af;">Console</span><span style="background: white;">.WriteLine(</span><span style="background: white; color: #a31515;">"Mail Sending.."</span><span style="background: white;">);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">enum</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">MessageType</span><span style="background: white;"> { Sms, Mail };<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">class</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">Program</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">static</span><span style="background: white;"> </span><span style="background: white; color: blue;">void</span><span style="background: white;"> Main(</span><span style="background: white; color: #2b91af;">String</span><span style="background: white;">[] args)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: #2b91af;">Dictionary</span><span style="background: white;"><</span><span style="background: white; color: #2b91af;">MessageType</span><span style="background: white;">, </span><span style="background: white; color: #2b91af;">IMessage</span><span style="background: white;">> ObjectFactory </span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> = </span><span style="background: white; color: blue;">new</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">Dictionary</span><span style="background: white;"><</span><span style="background: white; color: #2b91af;">MessageType</span><span style="background: white;">, </span><span style="background: white; color: #2b91af;">IMessage</span><span style="background: white;">><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> { </span><span style="background: white; color: #2b91af;">MessageType</span><span style="background: white;">.Sms, </span><span style="background: white; color: blue;">new</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">SMS</span><span style="background: white;">() },<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> { </span><span style="background: white; color: #2b91af;">MessageType</span><span style="background: white;">.Mail, </span><span style="background: white; color: blue;">new</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">Mail</span><span style="background: white;">() }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> };<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> System.</span><span style="background: white; color: #2b91af;">Console</span><span style="background: white;">.WriteLine(</span><span style="background: white; color: #a31515;">"0: For SMS, 1: Mail"</span><span style="background: white;">);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">int</span><span style="background: white;"> ReadType = </span><span style="background: white; color: #2b91af;">Convert</span><span style="background: white;">.ToInt32(</span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> System.</span><span style="background: white; color: #2b91af;">Console</span><span style="background: white;">.ReadLine());<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> ObjectFactory[(</span><span style="background: white; color: #2b91af;">MessageType</span><span style="background: white;">)ReadType].Send();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> <o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><span style="background: white;"> System.</span><span style="background: white; color: #2b91af;">Console</span><span style="background: white;">.ReadLine();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"> }<o:p></o:p></span></span></div>
<span style="background: white; line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;">}</span></span><br />
<span style="background: white; line-height: 107%;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><br /></span></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOD7qOdL5Ks0sYa6PTG_Q5o-IDB8B6KrcsI0STf29OSjaGhbgXdHT4d-N2JIkDzTPAoDsNmKTXY-Iq7cYySjfGt_f7NSexkBMrOmFZBVHrS6UTzQtY3dGx_Ms8wNanXbMYs1ylI15z1vQ/s1600/Avoid-If-Else_and_Switch.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: Georgia, Times New Roman, serif; font-size: large;"><img border="0" height="198" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOD7qOdL5Ks0sYa6PTG_Q5o-IDB8B6KrcsI0STf29OSjaGhbgXdHT4d-N2JIkDzTPAoDsNmKTXY-Iq7cYySjfGt_f7NSexkBMrOmFZBVHrS6UTzQtY3dGx_Ms8wNanXbMYs1ylI15z1vQ/s400/Avoid-If-Else_and_Switch.jpg" width="400" /></span></a></div>
<span style="background: white; font-family: Consolas; font-size: 9.5pt; line-height: 107%;"><br /></span></div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0tag:blogger.com,1999:blog-5565818621935638643.post-17992307927101378762015-11-14T19:50:00.001-08:002015-11-20T01:23:18.439-08:00This 12 changes you will encounter in ASP.NET 5 at first time.<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">If
you keep an eye on movement of ASP.NET5/VNext then probably you know that recently
the 8<sup>th</sup> beta version has released (at the time of writing this
post). Anyway, it looks like it will take another year to be stable and
production ready.<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKs1qb_rmJV8Kla9Fy3Yr9VEoDc18eC_G-V7JF_Xjs26qmshdrRauqiO6I3mCL-SWWAdixrFm_kXbKLS7zh1EljRaA-anPVPrb7710Vff86GSmzB3cSsvWfeh-3Mn1FtE1kI9KX857mKY/s1600/asp.netvnext.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"><img border="0" height="137" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKs1qb_rmJV8Kla9Fy3Yr9VEoDc18eC_G-V7JF_Xjs26qmshdrRauqiO6I3mCL-SWWAdixrFm_kXbKLS7zh1EljRaA-anPVPrb7710Vff86GSmzB3cSsvWfeh-3Mn1FtE1kI9KX857mKY/s400/asp.netvnext.jpg" width="400" /></span></a></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">It’s
good time to update our thought along with Microsoft. Here is few changes you
will notice in time of your first ASP.NET5 development.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoListParagraph" style="margin-bottom: 0.0001pt; text-indent: -0.25in;">
<!--[if !supportLists]--><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> <b>1) </b><b>First
time ASP.NET has become open source</b><o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 19.2pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">Yes,
though this is not part of ASP.NET5/VNext but this is great news for developer.
Now, then can study source code and process as per license and agreement.
Microsoft has made this wonderful decision to get better support from
community.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><b>2)
First time running on Linux and MAC or in self hosted process</b><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"> This is another great news. Now, it’s not
necessary to host your application only in IIS. This became possible because
new ASP.NET pipeline is no more dependent on System.Web. People can choose
other than Windows (hopefully, I doubt how many will really choose. Now a days
windows hosting too coming in cheap package like linux) to host there ASP.NET
application.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><b>3)
First time developers are using Other than VisualStudio(most probably)</b><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"> Probably, Microsoft too encourage people to
choose their own IDE. Officially you can use Sublime, Vim,Emacs etc. But again,
I doubt whether those IDE is best fit for enterprise!<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><b>4)
First time .NET is served as two modes(core and Full)</b><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"> Yes, Core and Full. If you don’t want backward
compatibility then blindly got for core CLR. Otherwise Full CLR. The full CLR
is nothing but the Old .NET Framework. The core CLR is only 11 MB in size and
very lean in design. This will help to execute unnecessary code in time of HTTP
execution. <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><b>5)
First time in built DI container (You can bring your own as well)</b><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"> Dependency Injection is common buzz in
modern software development. By keeping this mind Microsoft has provided one
simple DI container along with scaffolder template. Anyway you are welcome with
your favorite IoC container<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><b>6)
First time JSON based project setting structure.</b><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"> Yes, World is slowly adopting JSON as data
encoding scheme rather than XML. Same has reflected in project structure. In ASP.NET
5 project structure, you will find all JSON based setting file.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><b>7)
First time MVC and WebAPI are merged in same project.</b><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"> No more confusion between MVC controller
and API controller (Although, I never feel that it was confusing personally) Anyway,
It will bring uniformity in code base. <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><b>8)
First time Controller will work without controller keyword.</b><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"> One common interview Question has reduced.
Probably in time of MVC6 interview there is no scope to as Why “Controller”
suffix in name of controller blab la..J<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><b>9)
First time Output of server code change will reflect without build</b><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"> It’s a great help for developer. Those who
love/has background server side parsing language (like PHP) they will fall in
love of ASP.NET another time. The miracle happen by Roslyn compiler. <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><b>10)
You will get clear View of pipeline in Startup.cs file (I will not say this is
first time :))</b><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">Yes,
this is not first time feature but more clear then old MVC pipeline. The
components of MVC is very much pluggable now. Probably it’s time to say Goodbye
to HTTP handler and HTTP module. <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><b>11)
Your application will not more depend on System.web(If you wish)</b><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">Yes,
OWIN and KATANA will take care the communication between your application and
Web Server. So, it’s no longer need to get help of bulky System.Web assembly.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><b>12)
The default Unit test framework is XUnit.</b><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"> The earlier framework was Visual Studio
Unit test framework (vstest sometime). The XUnit framework has shipped along
with ASP.NET5. I did not find much change or feature in XUnit framework other
than some syntactical change.<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com1tag:blogger.com,1999:blog-5565818621935638643.post-64746398761156301512015-11-11T03:24:00.000-08:002015-11-20T01:26:21.126-08:00Who you are? Answer In light of Taittiriya Upanishad.<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Taittriya Upanishad is one of the old Sanskrit scripture of ancient
Vedas. In this article we will take certain part of this Upanishad and try to
understand “Who we are?” in the thought of it. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">The journey is to find who you really are and at last you
will find yourself as well as God. In almost all religion, it’s said that you
are the God you are the divine one etc., in this short metaphorical journey we
will really experience the same. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOeOVK_4YhsNm4cbjFTtXThGMvMPlBISIxBE5a4G-8m5m3r5tTSg8aLozAX7SmJIaXRtM-8qKI2IFW8Yk-Rwku2l_JVd8d8ocHEJ9NzXyT7EFTnY4BqTlzBYblHckHftwz5J9Ue9D1Qcg/s1600/controlcvprogrammer.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><img border="0" height="185" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOeOVK_4YhsNm4cbjFTtXThGMvMPlBISIxBE5a4G-8m5m3r5tTSg8aLozAX7SmJIaXRtM-8qKI2IFW8Yk-Rwku2l_JVd8d8ocHEJ9NzXyT7EFTnY4BqTlzBYblHckHftwz5J9Ue9D1Qcg/s400/controlcvprogrammer.jpg" width="400" /></span></a></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">There is Sufi (poem addressing Allah) poet who is said in
his song “I find myself when I try to search god, I find God when I try to
search myself”. This is the whole philosophy of this presentation.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Let’s start the journey to discover oneself.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Taittiriya Upanishad said, <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Question > Do you want to know yourself? <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Answer> Yes, of course. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Question> Ok, who you are? <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Answer> this is I am, the face, the hand, leg, eye etc.
In face I am the whole body!<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Ok, let’s start with that. The Upanishad is saying this body
as “Annayamaya Atma”. The body is made by Food. Yes, if you literally think
that, our body exist because we do eat. Just think that how much food we have
consumed in today? May be 2 K.g ! Ok, how much in last 7 days? 7X2= 14 Kg. and
how much in last year? 365X2 = 730 Kg and so on. Just think how much we have consumed in last
25 years! So, in broad sense, we do not see anything beyond food in body. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Ok, if the body which keeps on changing, is made with food. Upanishad
saying, you are not the body. The self which we are trying to find is not the
body. So, look within the body.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">What you will find within body? Upanishad said, there is “Pranamaya
Atma”. “Pranamaya Atma” means life. You
feel energetic, you feel hungry, sick, sad, and happy those are the functions
of life. So, we find, “Annayamaya Atma” is behaving as jacket over “Pranamaya
Atma”. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">So, the thought to be clear, we are not “Annayamaya Atma” (not
food) then are we “Pranamaya Atma”? Are we our life are we the sadness, happiness,
etc which is covered by our body?<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Upanishad says, No we are not the life, we are not “Pranayama
Atma”. Let’s come one step deeper from this.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">What is deeper than the life? Feel within, you will find
your mind. Thoughts, Feelings, Memory, Decisions all comes from your mind.
Upanishad is calling this as “Monamoya Atma”. People may identify him by
combining the mind and body. I mean, they may define that I am so and so and I did
so and so.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Do you think that the mind is what you are? No, you are not
the mind, because mind changes time to time based on your experience. It’s not
static and the Upanishad says, even that is not the self.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">The mind is nothing but a cover by your life which is again
covering by body. Let’s go next step from this. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Upanishad is saying. What do you use to use the mind? Impelled
by what the mind thinks? Why mind act? Who controls our mind? Upanishad is giving answer, it is “Intellect”
and Upanishad call it as “Vidayanamaya Atma”. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">So, the question comes, the intellect which we using is self?
No, because it too is dynamic. The intellect which you had years ago and the
intellect now, those are must be different. So, Upanishad is saying, Intellect
is not self, it’s too covering by mind.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">Let’s think something deeper than the intellect. What could
be beyond than the Intellect? Upanishad saying there is a blankness which exist
beyond intellect. Which we experience in deep sleep. Upanishad is calling this
as “Anandamaya Atma”<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">So, are we the blankness? Upanishad saying, no we are not blankness
because the blankness too is not permanent. We fall in sleep and week up, when
we weak up the blankness goes away.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">So, that is not self. Upanishad is concluding here, like
this. The self is “Which is experiencing all those Atmas”<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "helvetica neue" , "arial" , "helvetica" , sans-serif; font-size: large;">So, you are not your body-> You are not your life ->
You are not your mind -> You are not your Intellect-> You are not the blankness
beyond the Intellect. You are the one who is observing all those Atmas, all
those covers and this is the God.<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0tag:blogger.com,1999:blog-5565818621935638643.post-71614556207610909492015-11-06T08:18:00.000-08:002015-11-20T01:28:15.294-08:00How common man turns into satisfied customer?<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">In upcoming few paragraphs what you are going to read is
based on my experience and observation, not from any chapter of some
management/sales book.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwPkxK0MC5uWO8wvZgPIMfGoOY3wiiyoMZBOJ-pDsP8GNdJy3zYr-93Z1lq3zETtYtiI_qoi_jvCzy1_ew5AEmdIu9yo3LQHEkryg55WQBpVgXcm1QitCudNvO_mJO3VizWGx3IN08xII/s1600/Happy-Customer.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="145" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwPkxK0MC5uWO8wvZgPIMfGoOY3wiiyoMZBOJ-pDsP8GNdJy3zYr-93Z1lq3zETtYtiI_qoi_jvCzy1_ew5AEmdIu9yo3LQHEkryg55WQBpVgXcm1QitCudNvO_mJO3VizWGx3IN08xII/s400/Happy-Customer.jpg" width="400" /></a></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Sales and marketing are really an art and very few can able
to master on this. Teachers of your MBA School may tell you few points for
graceful selling but do not listen to them, if they have only academic background
till dateJ .
Because sales is an unique art which is
not possible to learn in B-school<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Ok, let’s come in core discussion. I have shifted in a new
place couple of months ago (due to my new job). Somehow, I managed a shelter to
stay and the entire atmosphere was new to me. The road, the people and the shops etc.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">After couple of days/weeks I started to explore nearby market,
started to talk to shopkeeper. I notice that I became comfortable with few
shops and like to visit always there for my daily commodities.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Now, the question came to my mind! Why the particular shop
in market? Although there are plenty of shops who sells same goods. Let’s analyses
few use case.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></b></div>
<div class="MsoNormal">
<b><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Case 1.<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">I always visit to a particular repairing shop for servicing
my two wheeler which is little far from my shelter though there is another one
just near to me.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Once I went to my nearby mechanical shop to fix one nut (In mirror
glass) which hardly cost 1 minute of there time (Let’s neglect usage cost of
tool and risk). They charge me 10 rupees for same. I got shocked by calculating
that, the cost of 1 minute of the mechanic is 5 time more than one average experienced
software engineer (Yes, I am J
) who is working for a MNC in silicon valley of India.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">After few days, the mirror got un-tight again and need to
fix. On the way of my office I found another mechanic shop who did it for no
price at all. I offered him same 10 rupees and asked why you will not charge?
He replied surprisingly! Sir, it’s too less effort, to charge any amount!<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"> Now, here is the point to focus. May be 10 rupees
is nothing neither to me nor to first motor shop but the 10 rupees has given birth
of an unsatisfied customer.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Needless to say, I became permanent customer of the second
motor shop.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></b></div>
<div class="MsoNormal">
<b><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Case 2.<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">I enjoy my drinking water service to my doorstep. Service
was going well, till the bad day when I was getting not reachable tune from the
shop keeper’s phone number contentiously. On the other side water is essential
need and the pot was near to empty. After long time, I could able to connect to
my shop keeper and he said he has come to his native so, cannot able to serve
water for few days because someone else is taking care of shop.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">I went to local market to find another vendor and saw one
guy was distributing water in his hand pull van. I talk to him, get contact
number along with new water connection.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Yes, so far he did not miss a single water refilling
request. <o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></b></div>
<div class="MsoNormal">
<b><span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Case 3.<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">I always like to buy vegetables because I cook myself. Earlier,
I used to not check price of each and individual vegetables but I one day I
noticed that the next shop is taking much genuine price than my current shop.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Another day, I bought a pack of milk from a shop and
discover that it got expire though it did not cross expire date. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">In next day I change shop and told the shopkeeper that I had
bad experience of buying milk and same should not repeat. She replied, Brother
just throw the milk packet on my face if it is not ok. Hu... nice confidence
and assurance, what customer exactly look for.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">Anyway, there are
tons of example which evolves around us. May be we do not notice each and every
one but each one is really valuable enough in business standpoint<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">The mechanic shop would not lose a customer unless he charge
unfair. The water vendor would not lose one customer if he communicate properly
before going to native. The vegetable vendor could hold one customer If he
would honest enough in pricing.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "georgia" , "times new roman" , serif; font-size: large;">So, always be genuine, if you are in business. Don’t forget
that, your competitor is sitting next to you.<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0tag:blogger.com,1999:blog-5565818621935638643.post-12700422235385545202015-11-01T01:46:00.000-07:002015-11-20T01:29:23.210-08:00Block controller from outer world using custom route configuration.<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">There are many ways to block/restrict controller from
outside world. Here is some possible solution for same<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> 1)<span style="font-stretch: normal;">
</span><!--[endif]-->We can writer custom filter to prevent the
controller from being execute and use the customer as attribute<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> </span></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"> 2)<span style="font-stretch: normal;">
</span><!--[endif]-->Within delegating handler we can write some code
to sniff controller from current http context and block there.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]--><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> </span></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"> 3)<span style="font-stretch: normal;">
</span><!--[endif]-->We can implement custom routing mechanism to
prevent some controller from being execute.<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">In this article we will implement custom route class by
implement IRouteConstant interface. The class can be use in time route
initialization. Let’s implement the class at first.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white; color: blue;"> public</span><span style="background: white;"> </span><span style="background: white; color: blue;">class</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">ExcludeController</span><span style="background: white;"> : </span><span style="background: white; color: #2b91af;">IRouteConstraint</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">private</span><span style="background: white;"> </span><span style="background: white; color: blue;">readonly</span><span style="background: white;"> </span><span style="background: white; color: blue;">string</span><span style="background: white;"> _controller;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> ExcludeController(</span><span style="background: white; color: blue;">string</span><span style="background: white;"> controller)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> _controller = controller;<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">bool</span><span style="background: white;"> Match(</span><span style="background: white; color: #2b91af;">HttpContextBase</span><span style="background: white;"> httpContext, </span><span style="background: white; color: #2b91af;">Route</span><span style="background: white;"> route, </span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white; color: blue;"> string</span><span style="background: white;"> parameterName, </span><span style="background: white; color: #2b91af;">RouteValueDictionary</span><span style="background: white;"> values, </span><span style="background: white; color: #2b91af;">RouteDirection</span><span style="background: white;"> routeDirection)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">return</span><span style="background: white;"> ! </span><span style="background: white; color: blue;">string</span><span style="background: white;">.Equals(values[</span><span style="background: white; color: #a31515;">"controller"</span><span style="background: white;">].ToString(),</span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> _controller, </span><span style="background: white; color: #2b91af;">StringComparison</span><span style="background: white;">.OrdinalIgnoreCase);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white; line-height: 107%;"> }</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background: white; line-height: 107%;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"><br /></span></span></div>
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">Formally, the class name is ExcludeController. We have
implemented Match() function within class. It will return false when current controller
name will equal to restricted controller name. Now, we have to fit the class in
route definition. Here is how, we can fit the class in route entry.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;">routes.MapRoute(<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> name: </span><span style="background: white; color: #a31515;">"Default"</span><span style="background: white;">,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> url: </span><span style="background: white; color: #a31515;">"{controller}/{action}/{id}"</span><span style="background: white;">,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> defaults: </span><span style="background: white; color: blue;">new</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> controller = </span><span style="background: white; color: #a31515;">"Home"</span><span style="background: white;">,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> action = </span><span style="background: white; color: #a31515;">"Index"</span><span style="background: white;">,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> id = </span><span style="background: white; color: #2b91af;">UrlParameter</span><span style="background: white;">.Optional<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> },<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> constraints: </span><span style="background: white; color: blue;">new</span><span style="background: white;"> { controller = </span><span style="background: white; color: blue;">new</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">ExcludeController</span><span style="background: white;">(</span><span style="background: white; color: #a31515;">"Configuration"</span><span style="background: white;">)
}<o:p></o:p></span></span></div>
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white; line-height: 107%;"> );</span><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">Please note that, we are passing parameter value “Configuration”
that implies, when request will come for Configuration controller it will just
ignore because Match() function will return false.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">Here is sample code for Configuration controller.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">class</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">ConfigurationController</span><span style="background: white;"> : </span><span style="background: white; color: #2b91af;">Controller</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">ActionResult</span><span style="background: white;"> Index()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">return</span><span style="background: white;"> </span><span style="background: white; color: blue;">new</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">EmptyResult</span><span style="background: white;">();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">And it’s throwing 404 result when we are trying to execute.<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw5p95wK77mc-KRjpHK0Lrj3ONbO2Bzycdxt7-rQKB-XBSMElX2VFVX0EdNmtoD7-VSfizvMQCWNGsY5bwSw2i2W_RecKQ6toBF0_R_6tA7WVE3e3V4UO9sNLiKHC9FPerV-5mH71keqc/s1600/BlockController.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"><img border="0" height="162" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw5p95wK77mc-KRjpHK0Lrj3ONbO2Bzycdxt7-rQKB-XBSMElX2VFVX0EdNmtoD7-VSfizvMQCWNGsY5bwSw2i2W_RecKQ6toBF0_R_6tA7WVE3e3V4UO9sNLiKHC9FPerV-5mH71keqc/s400/BlockController.jpg" width="400" /></span></a></div>
<div class="MsoNormal">
<br /></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0tag:blogger.com,1999:blog-5565818621935638643.post-91081194265472295122015-11-01T00:54:00.002-07:002015-11-20T01:30:35.886-08:00A simple MVC route configuration for RESTFul blog url.<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">In this article we will configure routing for simple blog
application in ASP.NET. The url will follow style of REST based url structure. Let’s understand the routing for same.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">class</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">RouteConfig</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">static</span><span style="background: white;"> </span><span style="background: white; color: blue;">void</span><span style="background: white;"> RegisterRoutes(</span><span style="background: white; color: #2b91af;">RouteCollection</span><span style="background: white;"> routes)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> routes.IgnoreRoute(</span><span style="background: white; color: #a31515;">"{resource}.axd/{*pathInfo}"</span><span style="background: white;">);<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> routes.MapRoute(<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> name: </span><span style="background: white; color: #a31515;">"YearAndMonth"</span><span style="background: white;">,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> url: </span><span style="background: white; color: #a31515;">"{controller}/{year}/{month}"</span><span style="background: white;">,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> defaults: </span><span style="background: white; color: blue;">new</span><span style="background: white;"> { controller = </span><span style="background: white; color: #a31515;">"post"</span><span style="background: white;">, </span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> action
= </span><span style="background: white; color: #a31515;">"PostByYearAndMonth"</span><span style="background: white;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> );<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> routes.MapRoute(<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: #a31515;">"PostByYear"</span><span style="background: white;">,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: #a31515;">"{controller}/{year}"</span><span style="background: white;">,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">new</span><span style="background: white;"> { controller = </span><span style="background: white; color: #a31515;">"post"</span><span style="background: white;">, action = </span><span style="background: white; color: #a31515;">"PostByYear"</span><span style="background: white;"> } ,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">new</span><span style="background: white;"> { year = </span><span style="background: white; color: #a31515;">@"\d+"</span><span style="background: white;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> );<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> routes.MapRoute(<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: #a31515;">"PostByAuthor"</span><span style="background: white;">,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: #a31515;">"{controller}/{name}"</span><span style="background: white;">,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">new</span><span style="background: white;"> { controller = </span><span style="background: white; color: #a31515;">"post"</span><span style="background: white;">, </span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> action = </span><span style="background: white; color: #a31515;">"PostByAuthor"</span><span style="background: white;"> }, </span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white; color: blue;"> new</span><span style="background: white;"> { name = </span><span style="background: white; color: #a31515;">@"^[a-zA-Z]+$"</span><span style="background: white;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> );<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> routes.MapRoute(<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> name: </span><span style="background: white; color: #a31515;">"Default"</span><span style="background: white;">,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> url: </span><span style="background: white; color: #a31515;">"{controller}/{action}/{id}"</span><span style="background: white;">,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> defaults: </span><span style="background: white; color: blue;">new</span><span style="background: white;"> { controller = </span><span style="background: white; color: #a31515;">"Home"</span><span style="background: white;">, </span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> action
= </span><span style="background: white; color: #a31515;">"Index"</span><span style="background: white;">, id = </span><span style="background: white; color: #2b91af;">UrlParameter</span><span style="background: white;">.Optional }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> );<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> <o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">We have defined couple of route for different type of
request. Here is the controller implementation to support those routes.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"><br /></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: blue;">class</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">postController</span><span style="background: white;"> : </span><span style="background: white; color: #2b91af;">Controller</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: green;">//Get
all posts </span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: green;">//ex.
post</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">ActionResult</span><span style="background: white;"> Index()<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">return</span><span style="background: white;"> </span><span style="background: white; color: blue;">new</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">EmptyResult</span><span style="background: white;">();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: green;">//Post
by Author name</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: green;">//ex.
post/sourav</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">ActionResult</span><span style="background: white;"> PostByAuthor(</span><span style="background: white; color: blue;">string</span><span style="background: white;"> name)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">return</span><span style="background: white;"> </span><span style="background: white; color: blue;">new</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">EmptyResult</span><span style="background: white;">();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: green;">//Post
by year</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: green;">//ex.
post/2015</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">ActionResult</span><span style="background: white;"> PostByYear(</span><span style="background: white; color: blue;">int</span><span style="background: white;"> year)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">return</span><span style="background: white;"> </span><span style="background: white; color: blue;">new</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">EmptyResult</span><span style="background: white;">();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: green;">//post
by year and month</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: green;">//ex.
post/2015/2</span><span style="background: white;"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">public</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">ActionResult</span><span style="background: white;"> PostByYearAndMonth(</span><span style="background: white; color: blue;">int</span><span style="background: white;"> year, </span><span style="background: white; color: blue;">int</span><span style="background: white;"> month)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> {<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;"><span style="background: white;"> </span><span style="background: white; color: blue;">return</span><span style="background: white;"> </span><span style="background: white; color: blue;">new</span><span style="background: white;"> </span><span style="background: white; color: #2b91af;">EmptyResult</span><span style="background: white;">();<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white;"><span style="font-family: "times" , "times new roman" , serif; font-size: large;"> }<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: "times" , "times new roman" , serif; font-size: large;">Please have a look that routing entry for “PostByYear”
taking year parameter which is restricted to integer type and “name” parameter
in PostByAuthor is restricted to string. So, when we will pass integer value
from route it will hit “PostByYear” action and when the parameter is string
type, it will hit to “PostByAuthor” action.<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0tag:blogger.com,1999:blog-5565818621935638643.post-9305803247713870022015-10-31T05:20:00.000-07:002015-10-31T05:21:00.957-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: large;">A large amount of today’s financial ecosystem is depending on
Startup Company. In last few years startup ecosystem in India has stretched
like anything. We can see plenty of startups in each and every sector, some of
them are really doing well.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil9O_dUSCDCIZ8_qgdDT2sSCmbz6gX1-aUBKYKiIcawOb_oPyTKRjidGhQxDWUw3DGaBPxzqaDouzLnHBAlfnFQQ1p9WXqgw99ekX7cwM5biVty4n0ekPFn0fJoCpj8QCfPYWb2vclII4/s1600/logo_white_bg.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="75" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEil9O_dUSCDCIZ8_qgdDT2sSCmbz6gX1-aUBKYKiIcawOb_oPyTKRjidGhQxDWUw3DGaBPxzqaDouzLnHBAlfnFQQ1p9WXqgw99ekX7cwM5biVty4n0ekPFn0fJoCpj8QCfPYWb2vclII4/s400/logo_white_bg.jpg" width="400" /></a></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: large;">Anyway,<a href="http://blog.venturestop.com/Post/SubmitStory" target="_blank"> <span style="color: red;">venturestop.com</span></a> is a digital media platform to
promote startup’s success story in free. </span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: large;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: large;">If </span><span style="font-family: Verdana, sans-serif; font-size: large;">you are founder/CEO of any startup
and want to promote your company in free, please share your company’s
information with us, we will create one nice article from this information and
promote in our media.</span></div>
<br />
<div class="MsoNormal">
<span style="font-family: Verdana, sans-serif; font-size: large;">It’s in free. </span><o:p></o:p></div>
</div>
testsouravkayalhttp://www.blogger.com/profile/01705937011716402571noreply@blogger.com0