SlideShare a Scribd company logo
1 of 28
© Instil Software 2017
October 2017
eamonn.boyle@instil.coeamonn.boyle@instil.cogarth.gilmour@instil.co | eamonn.boyle@instil.co
ASP .NET Core
New SPA Templates
© Instil Software 2017
• I want new people on-boarded as quickly as possible
• I want to be able to add new features easily
• I want computers to do most of my work for me
• I don’t want the headache and hassle of bugs
Who am I?
© Instil Software 2017
Release Notes
• Razor Pages
• Single ASP .NET Core & EF Core meta-package
• Microsoft.AspNetCore.All
• Uses the Runtime Store
• Minor API Changes
• Logging, Configuration, WebBuilder
• Major API Changes
• Authentication, Identity, WebListener-> Http.sys
• New Single Page Application (SPA) Templates
• React [+ Redux], Angular and more
• Major Kestrel Updates – Internet Facing Supported
• Razor Pre-compilation
• And more…
ASP .NET Core 2.0
© Instil Software 2017
Release Notes
• Razor Pages
• Single ASP .NET Core & EF Core meta-package
• Microsoft.AspNetCore.All
• Uses the Runtime Store
• Minor API Changes
• Logging, Configuration, WebBuilder
• Major API Changes
• Authentication, Identity, WebListener-> Http.sys
• New Single Page Application (SPA) Templates
• React [+ Redux], Angular
• Major Kestrel Updates – Internet Facing Supported
• Razor Pre-compilation
• And more…
ASP .NET Core 2.0
© Instil Software 2017
Web Applications originally relied heavily on server side rendering:
Pros
• Templating frameworks easy for basic content
• Encapsulates business logic
• Small initial downloads for user/browser
• Works well with SEO
Cons
• Limited user experience -> Page Refreshes
• Over time, more data transferred – feels slower
• Heavy load on server
Server Side Rendering
© Instil Software 2017
The Single Page Application Concept
Service A
Service B
Service C
Single Page
Application
JSON
JSON
JSON
Web Server
Static Files
HTML, CSS, JS
We’ve moved to rich client-side experiences
• AJAX + jQuery and then on to UI frameworks –
Angular, React, Vue…..
© Instil Software 2017
Pros
• Separation of Concerns – Client-Server
• Very rich UX
• Only data transferred during interaction
• Lower load on server
• Easy deployment – static files
Cons
• Slow initial load – vendor download
• Does not play well with SEO
• Complex build mechanism
• Complex content definition
Single Page Application (SPA)
© Instil Software 2017
Foundations of Front End
“JavaScript is the VM of the web”
Douglas Crockford
© Instil Software 2017
The Evolution of JavaScript Frameworks
Angular 2/4
React
Angular 1DojojQueryManual
Scripting
HTML
© Instil Software 2017
Like a kid in a candy store…
© Instil Software 2017
Module Counts
http://www.modulecounts.com/
npm Package Count 
532,293
https://www.statista.com
Programmers in the UK 
292,000
© Instil Software 2017
TypeScript (aka TS) is a superset of JavaScript
• Created by Anders Hejlsberg at Microsoft
• Released as an open source project (Apache 2 License)
The language is transpiled into JavaScript
• The compiler is written in TS and runs on top of Node.js
• It can be used for both client and server side applications
Programming in TypeScript allows you to:
• Use the language features defined in ECMAScript 2015
• Add type declarations to variables, parameters etc…
• Make use of more advanced features like generics
Introducing TypeScript
© Instil Software 2017
JavaScriptServices is a series of packages for using client-side technologies
• Microsoft.AspNetCore.NodeServices
• Microsoft.AspNetCore.SpaServices
• Microsoft.AspNetCore.SpaTemplates
Useful when
• Run JavaScript on the server
• Use a SPA framework or library
• Build client-side assets with Webpack
JavaScriptServices
© Instil Software 2017
React and Angular templates are now included as part of .NET Core SDK 2.0
More templates can be installed via:
“dotnet new --install Microsoft.AspNetCore.SpaTemplates::*”
SpaTemplates
Templates Short Name
----------------------------------------------------------------
Console Application console
Class library classlib
Unit Test Project mstest
xUnit Test Project xunit
ASP.NET Core Empty web
ASP.NET Core Web App (Model-View-Controller) mvc
ASP.NET Core Web App razor
ASP.NET Core with Aurelia aurelia
ASP.NET Core with Knockout.js knockout
ASP.NET Core with Vue.js vue
ASP.NET Core with Angular angular
ASP.NET Core with React.js react
ASP.NET Core with React.js and Redux reactredux
ASP.NET Core Web API webapi
© Instil Software 2017
A TypeScript based web app platform
• Open source – led by team at Google
• Replaces AngularJS
• Provides services for UI, communication, DI etc
UI decomposed into components
• Follows an MVC pattern
• HTML for the View – annotated with special directives
• Component localised CSS for styling
• TypeScript for component Code Behind
• Augmented with other services, model etc.
Angular
@Component({
selector: ‘app-menubar',
templateUrl: ‘./menubar.component.html’
styleUrls: [‘./menubar.component.css’]
})
export class FetchDataComponent {
<h1>This is a HTML file</h1>
<app-menubar></app-menubar>
© Instil Software 2017
React is a front end UI framework
• Open source – led by Facebook
• Unlike Angular, it focuses only on UI
• Some libraries are commonly paired e.g. Redux
UI decomposed into components
• Defined completely in code
• Components define a ‘render’ method
• This returns a component tree
• JSX makes creating objects like writing HTML
React
export class Weather extends React.Component {
constructor() {
super();
}
public render() {
return <div>
<h1>This is JSX</h1>
<WeatherTable></WeatherTable>
</div>;
}
}
© Instil Software 2017
Comparing Angular 4 & React.js
Angular React
UI built using non-standard expressions
and directives in HTML
UI built using pure JavaScript
(though uses transpiled JSX)
Two way binding Unidirectional data flow
Decouples view from state State and view coupled
Performance impacts with complexity Fast due to data model
More complete framework
Many services e.g. REST, Browser etc
Only the view library
Angular 4 is TypeScript Pure JavaScript**
Google Facebook
© Instil Software 2017
NodeServices allow us to run JavaScript easily from within .NET code
• Runs Node.js in the background
• Uses an async API
• Can easily pass parameters, return results and catch errors
NodeServices
© Instil Software 2017
module.exports = function(callback, name) {
if (!name) {
callback("Error - no name provided", "Value not used");
}
else {
callback(null, "Hello " + name);
}
}
Node/HelloWorld.js
Invoking JavaScript from Within C#
© Instil Software 2017
[Route("api/[controller]")]
public class NodeController : Controller {
private readonly INodeServices nodeServices;
public NodeController(INodeServices nodeServices) {
this.nodeServices = nodeServices;
}
[HttpGet("HelloWorld/{name?}")]
public async Task<string> GetHelloWorld(string name) {
try {
return await nodeServices.InvokeAsync<string>("Node/HelloWorld", name);
}
catch (NodeInvocationException e) {
return "Caught error from Node - " + e.Message;
}
}
}
NodeController.cs
Invoking JavaScript from Within C#
© Instil Software 2017
Makes developing Single Page Applications with a .NET backend easier
• Builds upon NodeServices where Node.js is required
• SpaServices allows the development of the two to be more aligned
• Single server providing content and services
We can keep our backend services and client side projects separated
• Clear separation of client/server
• Optimised workflows
• Separate tooling
• Seaparate teams
SpaServices
© Instil Software 2017
Provides useful features such as:
• Server-side prerendering
• Webpack Dev Middleware & Hot Module Replacement
• Routing helpers
What you will need:
• Node version 6+
• ASP .NET Core 2.0
SpaServices
© Instil Software 2017
Server Side Rendering  Client Side Rendering  Universal / Isomorphic
Now universal or isomorphic applications are desirable
• JavaScript rendering on client and server
• Compromise between both worlds
• Popular client side frameworks offer support – Angular, React….
Pros
• Very rich UX
• Fast initial load with prerendered content
• Only data transferred during interaction
• Same technology used throughout
• Works well with SEO
Server Side Prerendering
© Instil Software 2017
SpaServices helps with server side prerendering
• Tag helpers within Razor for easy integration
The PrerenderTagHelper provides tag helpers to load prerendered content
• ‘asp-prerender-module’ – run a specified JavaScript file that does pre-rendering
• The script has a defined structured
• Uses elements from ‘aspnet-prerendering’ package
• ‘asp-prerender-data’ – pass data into the prerender script
Server Side Prerendering
<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
<script src="~/dist/vendor.js" asp-append-version="true"></script>
@section scripts {
<script src="~/dist/main-client.js" asp-append-version="true"></script>
}
Index.cshtml
© Instil Software 2017
Webpack allows you to write your code in a modular, well-designed and scalable
way while still reducing runtime communication (fewer and smaller requests)
Webpack Dev Middleware
© Instil Software 2017
The Webpack Dev Middleware recompiles the client code while running
• Code watched and rebundled
• With Hot Module Replacement, the browser page is automatically reloaded
Enabling the Webpack Dev Middleware
public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions {
HotModuleReplacement = true
});
}
else {
app.UseExceptionHandler("/Home/Error");
}
Startup.cs
© Instil Software 2017
We have routing on the server and internal within the SPA
Routes not known to the server should resolve to the SPA
• Routes that look like static files (extensions) will not resolve to the SPA
Routing Helper
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" });
});
Startup.cs
© Instil Software 2017
• The SPA templates provide quick solution for ASP .NET Core
• A few commands and you have a functioning app you can expand
• Keeps everything in one place
• Good example of desired build properties
• Optimised bundling
• Watch and Hot Module Replacement
• Prerendering for faster initial page loads
But…
• Tooling is currently sub-optimal compared to separate projects
• There are better SPA centric workflows
• E.g. Angular CLI + WebStorm / Visual Studio Code
Summary

More Related Content

What's hot

Dnc2015 azure-microservizi-vforusso
Dnc2015 azure-microservizi-vforussoDnc2015 azure-microservizi-vforusso
Dnc2015 azure-microservizi-vforusso
DotNetCampus
 

What's hot (20)

Serverless Application Development with Azure
Serverless Application Development with AzureServerless Application Development with Azure
Serverless Application Development with Azure
 
Azure and web sites hackaton deck
Azure and web sites hackaton deckAzure and web sites hackaton deck
Azure and web sites hackaton deck
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
 
Azure Container Apps
Azure Container AppsAzure Container Apps
Azure Container Apps
 
Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture Anatomy of a Modern Node.js Application Architecture
Anatomy of a Modern Node.js Application Architecture
 
Azure cloud for the web frontend developers
Azure cloud for the web frontend developersAzure cloud for the web frontend developers
Azure cloud for the web frontend developers
 
Write Once, Run Everywhere - Ember.js Munich
Write Once, Run Everywhere - Ember.js MunichWrite Once, Run Everywhere - Ember.js Munich
Write Once, Run Everywhere - Ember.js Munich
 
Dnc2015 azure-microservizi-vforusso
Dnc2015 azure-microservizi-vforussoDnc2015 azure-microservizi-vforusso
Dnc2015 azure-microservizi-vforusso
 
Let's play with adf 3.0
Let's play with adf 3.0Let's play with adf 3.0
Let's play with adf 3.0
 
Adobe AEM for Business Heads
Adobe AEM for Business HeadsAdobe AEM for Business Heads
Adobe AEM for Business Heads
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
React.js for Rails Developers
React.js for Rails DevelopersReact.js for Rails Developers
React.js for Rails Developers
 
Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...
 
Swagger code motion talk
Swagger code motion talkSwagger code motion talk
Swagger code motion talk
 
Creating Real-Time Data Mashups with Node.JS and Adobe CQ
Creating Real-Time Data Mashups with Node.JS and Adobe CQCreating Real-Time Data Mashups with Node.JS and Adobe CQ
Creating Real-Time Data Mashups with Node.JS and Adobe CQ
 
React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016React on rails v6.1 at LA Ruby, November 2016
React on rails v6.1 at LA Ruby, November 2016
 
ASP.NET Brief History
ASP.NET Brief HistoryASP.NET Brief History
ASP.NET Brief History
 
O365Con18 - Automate your Tasks through Azure Functions - Elio Struyf
O365Con18 - Automate your Tasks through Azure Functions - Elio StruyfO365Con18 - Automate your Tasks through Azure Functions - Elio Struyf
O365Con18 - Automate your Tasks through Azure Functions - Elio Struyf
 
Azure functions serverless
Azure functions serverlessAzure functions serverless
Azure functions serverless
 
Enterprise Java on Microsoft Azure: From Java EE to Spring, we’ve got you cov...
Enterprise Java on Microsoft Azure: From Java EE to Spring, we’ve got you cov...Enterprise Java on Microsoft Azure: From Java EE to Spring, we’ve got you cov...
Enterprise Java on Microsoft Azure: From Java EE to Spring, we’ve got you cov...
 

Similar to ASP .Net Core SPA Templates

SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4
Jon Galloway
 
Amit Kumar Architect with Web and Angular JS
Amit Kumar Architect with Web and Angular JSAmit Kumar Architect with Web and Angular JS
Amit Kumar Architect with Web and Angular JS
Amit Kumar
 

Similar to ASP .Net Core SPA Templates (20)

ASP.NET Core 1.0
ASP.NET Core 1.0ASP.NET Core 1.0
ASP.NET Core 1.0
 
Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015Best of Microsoft Dev Camp 2015
Best of Microsoft Dev Camp 2015
 
SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4SoCal Code Camp 2011 - ASP.NET MVC 4
SoCal Code Camp 2011 - ASP.NET MVC 4
 
ASP.NET Presentation
ASP.NET PresentationASP.NET Presentation
ASP.NET Presentation
 
The future of web development write once, run everywhere with angular js an...
The future of web development   write once, run everywhere with angular js an...The future of web development   write once, run everywhere with angular js an...
The future of web development write once, run everywhere with angular js an...
 
The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...The future of web development write once, run everywhere with angular.js and ...
The future of web development write once, run everywhere with angular.js and ...
 
ASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web AppsASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web Apps
 
ASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web AppsASP.NET Core 2.1: The Future of Web Apps
ASP.NET Core 2.1: The Future of Web Apps
 
Amit Kumar Architect with Web and Angular JS
Amit Kumar Architect with Web and Angular JSAmit Kumar Architect with Web and Angular JS
Amit Kumar Architect with Web and Angular JS
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
White Paper : ASP.NET Core AngularJs 2 and Prime
White Paper : ASP.NET Core AngularJs 2 and PrimeWhite Paper : ASP.NET Core AngularJs 2 and Prime
White Paper : ASP.NET Core AngularJs 2 and Prime
 
SPUnite17 Building Great Client Side Web Parts with SPFx
SPUnite17 Building Great Client Side Web Parts with SPFxSPUnite17 Building Great Client Side Web Parts with SPFx
SPUnite17 Building Great Client Side Web Parts with SPFx
 
MVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelMVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming model
 
Angular Meetup 1 - Angular Basics and Workshop
Angular Meetup 1 - Angular Basics and WorkshopAngular Meetup 1 - Angular Basics and Workshop
Angular Meetup 1 - Angular Basics and Workshop
 
The next step from Microsoft - Vnext (Srdjan Poznic)
The next step from Microsoft - Vnext (Srdjan Poznic)The next step from Microsoft - Vnext (Srdjan Poznic)
The next step from Microsoft - Vnext (Srdjan Poznic)
 
ASP.NET Core
ASP.NET CoreASP.NET Core
ASP.NET Core
 
Asp.NETZERO - A Workshop Presentation by Citytech Software
Asp.NETZERO - A Workshop Presentation by Citytech SoftwareAsp.NETZERO - A Workshop Presentation by Citytech Software
Asp.NETZERO - A Workshop Presentation by Citytech Software
 
Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure F...
Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure F...Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure F...
Tokyo Azure Meetup #7 - Introduction to Serverless Architectures with Azure F...
 
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
DevOps, Continuous Integration and Deployment on AWS: Putting Money Back into...
 
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
 

More from Eamonn Boyle

More from Eamonn Boyle (8)

Kotlin for Android - Goto Copenhagan 2019
Kotlin for Android - Goto Copenhagan 2019Kotlin for Android - Goto Copenhagan 2019
Kotlin for Android - Goto Copenhagan 2019
 
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
Kotlin Native - C / Swift Interop - ACCU Autmn 2019Kotlin Native - C / Swift Interop - ACCU Autmn 2019
Kotlin Native - C / Swift Interop - ACCU Autmn 2019
 
2019-06 - Goto Amsterdam - Microservices
2019-06 - Goto Amsterdam - Microservices2019-06 - Goto Amsterdam - Microservices
2019-06 - Goto Amsterdam - Microservices
 
2019-01-29 - Demystifying Kotlin Coroutines
2019-01-29 - Demystifying Kotlin Coroutines2019-01-29 - Demystifying Kotlin Coroutines
2019-01-29 - Demystifying Kotlin Coroutines
 
Kotlin for all the Things
Kotlin for all the ThingsKotlin for all the Things
Kotlin for all the Things
 
BelTech 2017 - Building Quality in the Browser
BelTech 2017 - Building Quality in the BrowserBelTech 2017 - Building Quality in the Browser
BelTech 2017 - Building Quality in the Browser
 
Being Expressive in Code
Being Expressive in CodeBeing Expressive in Code
Being Expressive in Code
 
2018-09 - F# and Fable
2018-09 - F# and Fable2018-09 - F# and Fable
2018-09 - F# and Fable
 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Recently uploaded (20)

W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 

ASP .Net Core SPA Templates

  • 1. © Instil Software 2017 October 2017 eamonn.boyle@instil.coeamonn.boyle@instil.cogarth.gilmour@instil.co | eamonn.boyle@instil.co ASP .NET Core New SPA Templates
  • 2. © Instil Software 2017 • I want new people on-boarded as quickly as possible • I want to be able to add new features easily • I want computers to do most of my work for me • I don’t want the headache and hassle of bugs Who am I?
  • 3. © Instil Software 2017 Release Notes • Razor Pages • Single ASP .NET Core & EF Core meta-package • Microsoft.AspNetCore.All • Uses the Runtime Store • Minor API Changes • Logging, Configuration, WebBuilder • Major API Changes • Authentication, Identity, WebListener-> Http.sys • New Single Page Application (SPA) Templates • React [+ Redux], Angular and more • Major Kestrel Updates – Internet Facing Supported • Razor Pre-compilation • And more… ASP .NET Core 2.0
  • 4. © Instil Software 2017 Release Notes • Razor Pages • Single ASP .NET Core & EF Core meta-package • Microsoft.AspNetCore.All • Uses the Runtime Store • Minor API Changes • Logging, Configuration, WebBuilder • Major API Changes • Authentication, Identity, WebListener-> Http.sys • New Single Page Application (SPA) Templates • React [+ Redux], Angular • Major Kestrel Updates – Internet Facing Supported • Razor Pre-compilation • And more… ASP .NET Core 2.0
  • 5. © Instil Software 2017 Web Applications originally relied heavily on server side rendering: Pros • Templating frameworks easy for basic content • Encapsulates business logic • Small initial downloads for user/browser • Works well with SEO Cons • Limited user experience -> Page Refreshes • Over time, more data transferred – feels slower • Heavy load on server Server Side Rendering
  • 6. © Instil Software 2017 The Single Page Application Concept Service A Service B Service C Single Page Application JSON JSON JSON Web Server Static Files HTML, CSS, JS We’ve moved to rich client-side experiences • AJAX + jQuery and then on to UI frameworks – Angular, React, Vue…..
  • 7. © Instil Software 2017 Pros • Separation of Concerns – Client-Server • Very rich UX • Only data transferred during interaction • Lower load on server • Easy deployment – static files Cons • Slow initial load – vendor download • Does not play well with SEO • Complex build mechanism • Complex content definition Single Page Application (SPA)
  • 8. © Instil Software 2017 Foundations of Front End “JavaScript is the VM of the web” Douglas Crockford
  • 9. © Instil Software 2017 The Evolution of JavaScript Frameworks Angular 2/4 React Angular 1DojojQueryManual Scripting HTML
  • 10. © Instil Software 2017 Like a kid in a candy store…
  • 11. © Instil Software 2017 Module Counts http://www.modulecounts.com/ npm Package Count  532,293 https://www.statista.com Programmers in the UK  292,000
  • 12. © Instil Software 2017 TypeScript (aka TS) is a superset of JavaScript • Created by Anders Hejlsberg at Microsoft • Released as an open source project (Apache 2 License) The language is transpiled into JavaScript • The compiler is written in TS and runs on top of Node.js • It can be used for both client and server side applications Programming in TypeScript allows you to: • Use the language features defined in ECMAScript 2015 • Add type declarations to variables, parameters etc… • Make use of more advanced features like generics Introducing TypeScript
  • 13. © Instil Software 2017 JavaScriptServices is a series of packages for using client-side technologies • Microsoft.AspNetCore.NodeServices • Microsoft.AspNetCore.SpaServices • Microsoft.AspNetCore.SpaTemplates Useful when • Run JavaScript on the server • Use a SPA framework or library • Build client-side assets with Webpack JavaScriptServices
  • 14. © Instil Software 2017 React and Angular templates are now included as part of .NET Core SDK 2.0 More templates can be installed via: “dotnet new --install Microsoft.AspNetCore.SpaTemplates::*” SpaTemplates Templates Short Name ---------------------------------------------------------------- Console Application console Class library classlib Unit Test Project mstest xUnit Test Project xunit ASP.NET Core Empty web ASP.NET Core Web App (Model-View-Controller) mvc ASP.NET Core Web App razor ASP.NET Core with Aurelia aurelia ASP.NET Core with Knockout.js knockout ASP.NET Core with Vue.js vue ASP.NET Core with Angular angular ASP.NET Core with React.js react ASP.NET Core with React.js and Redux reactredux ASP.NET Core Web API webapi
  • 15. © Instil Software 2017 A TypeScript based web app platform • Open source – led by team at Google • Replaces AngularJS • Provides services for UI, communication, DI etc UI decomposed into components • Follows an MVC pattern • HTML for the View – annotated with special directives • Component localised CSS for styling • TypeScript for component Code Behind • Augmented with other services, model etc. Angular @Component({ selector: ‘app-menubar', templateUrl: ‘./menubar.component.html’ styleUrls: [‘./menubar.component.css’] }) export class FetchDataComponent { <h1>This is a HTML file</h1> <app-menubar></app-menubar>
  • 16. © Instil Software 2017 React is a front end UI framework • Open source – led by Facebook • Unlike Angular, it focuses only on UI • Some libraries are commonly paired e.g. Redux UI decomposed into components • Defined completely in code • Components define a ‘render’ method • This returns a component tree • JSX makes creating objects like writing HTML React export class Weather extends React.Component { constructor() { super(); } public render() { return <div> <h1>This is JSX</h1> <WeatherTable></WeatherTable> </div>; } }
  • 17. © Instil Software 2017 Comparing Angular 4 & React.js Angular React UI built using non-standard expressions and directives in HTML UI built using pure JavaScript (though uses transpiled JSX) Two way binding Unidirectional data flow Decouples view from state State and view coupled Performance impacts with complexity Fast due to data model More complete framework Many services e.g. REST, Browser etc Only the view library Angular 4 is TypeScript Pure JavaScript** Google Facebook
  • 18. © Instil Software 2017 NodeServices allow us to run JavaScript easily from within .NET code • Runs Node.js in the background • Uses an async API • Can easily pass parameters, return results and catch errors NodeServices
  • 19. © Instil Software 2017 module.exports = function(callback, name) { if (!name) { callback("Error - no name provided", "Value not used"); } else { callback(null, "Hello " + name); } } Node/HelloWorld.js Invoking JavaScript from Within C#
  • 20. © Instil Software 2017 [Route("api/[controller]")] public class NodeController : Controller { private readonly INodeServices nodeServices; public NodeController(INodeServices nodeServices) { this.nodeServices = nodeServices; } [HttpGet("HelloWorld/{name?}")] public async Task<string> GetHelloWorld(string name) { try { return await nodeServices.InvokeAsync<string>("Node/HelloWorld", name); } catch (NodeInvocationException e) { return "Caught error from Node - " + e.Message; } } } NodeController.cs Invoking JavaScript from Within C#
  • 21. © Instil Software 2017 Makes developing Single Page Applications with a .NET backend easier • Builds upon NodeServices where Node.js is required • SpaServices allows the development of the two to be more aligned • Single server providing content and services We can keep our backend services and client side projects separated • Clear separation of client/server • Optimised workflows • Separate tooling • Seaparate teams SpaServices
  • 22. © Instil Software 2017 Provides useful features such as: • Server-side prerendering • Webpack Dev Middleware & Hot Module Replacement • Routing helpers What you will need: • Node version 6+ • ASP .NET Core 2.0 SpaServices
  • 23. © Instil Software 2017 Server Side Rendering  Client Side Rendering  Universal / Isomorphic Now universal or isomorphic applications are desirable • JavaScript rendering on client and server • Compromise between both worlds • Popular client side frameworks offer support – Angular, React…. Pros • Very rich UX • Fast initial load with prerendered content • Only data transferred during interaction • Same technology used throughout • Works well with SEO Server Side Prerendering
  • 24. © Instil Software 2017 SpaServices helps with server side prerendering • Tag helpers within Razor for easy integration The PrerenderTagHelper provides tag helpers to load prerendered content • ‘asp-prerender-module’ – run a specified JavaScript file that does pre-rendering • The script has a defined structured • Uses elements from ‘aspnet-prerendering’ package • ‘asp-prerender-data’ – pass data into the prerender script Server Side Prerendering <app asp-prerender-module="ClientApp/dist/main-server">Loading...</app> <script src="~/dist/vendor.js" asp-append-version="true"></script> @section scripts { <script src="~/dist/main-client.js" asp-append-version="true"></script> } Index.cshtml
  • 25. © Instil Software 2017 Webpack allows you to write your code in a modular, well-designed and scalable way while still reducing runtime communication (fewer and smaller requests) Webpack Dev Middleware
  • 26. © Instil Software 2017 The Webpack Dev Middleware recompiles the client code while running • Code watched and rebundled • With Hot Module Replacement, the browser page is automatically reloaded Enabling the Webpack Dev Middleware public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions { HotModuleReplacement = true }); } else { app.UseExceptionHandler("/Home/Error"); } Startup.cs
  • 27. © Instil Software 2017 We have routing on the server and internal within the SPA Routes not known to the server should resolve to the SPA • Routes that look like static files (extensions) will not resolve to the SPA Routing Helper app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new { controller = "Home", action = "Index" }); }); Startup.cs
  • 28. © Instil Software 2017 • The SPA templates provide quick solution for ASP .NET Core • A few commands and you have a functioning app you can expand • Keeps everything in one place • Good example of desired build properties • Optimised bundling • Watch and Hot Module Replacement • Prerendering for faster initial page loads But… • Tooling is currently sub-optimal compared to separate projects • There are better SPA centric workflows • E.g. Angular CLI + WebStorm / Visual Studio Code Summary