SlideShare a Scribd company logo
Building Blocks of
Angular 2 and ASP.NET Core
By Levi Fuller
Overview
• Angular CLI
• Overview & Commands
• Angular 2
• Overview
• Template Binding
• Decorators
• Lifecycle Hooks
• Directives
• Components
• Pipes
• Injectables (Services)
• Modules
• ASP.NET Core
• Overview
• Commands / Files
• Dependency Injection
• Controllers
• Pet Store Demo
Angular CLI
What is the Angular CLI?
Provides a set of commands which enable
you to:
• Scaffold a new app
• Scaffold the building blocks
• Run the application
• Build the application
• Deploy it
Scaffold Usage
Component ng g component my-new-component
Directive ng g directive my-new-directive
Pipe ng g pipe my-new-pipe
Service ng g service my-new-service
Class ng g class my-new-class
Interface ng g interface my-new-interface
Enum ng g enum my-new-enum
Module ng g module my-module
NG2 with the Angular CLI
• ng new <app-name>
• Creates new directory and creates the app
scaffolding inside the new directory
• ng serve
• Runs the application in memory via LiveReload server
• ng build
• Compiles the application and copies the output to
the `dist` directory
• ng github-pages:deploy
• Builds the app, setups a GitHub repo, publishes to
the GitHub page
Angular 2
Angular 2 Overview
Open source, front-end
framework for developing Single
Page Application (SPA’s)
• Supports TypeScript, Dart, or
JavaScript
• Component-based architecture
• Up to 5x faster than AngularJS
pet-
card.compo
nent
pet-
card.compo
nent
pet.options
app.component
Browse-pets.component
Data Binding
Data binding is the mechanism for coordinating what users see with the
component’s data values
<input type=“text” value=“Levi”>
{{person.name + ‘ is ’ + getAge(person.birthday)}}
<input [value]=“person.name”>
<input (input)=“name=$event.target.value”>
<input [(ngModel)]=“name”>
<input [ngModel]=“name” (ngModelChange)=“name=$event.target.value”>
<input [value]=“name” (input)=“name=$event.target.value”>
One-Time Initialization
This is not data binding
Event Binding
One-Way from view to
data source
Two-Way Binding
Property Binding +
Event Binding
Interpolation, Property,
Attribute, Class, and
Style Binding
Data source to view
One-WayTwo-Way
Template Binding Example
app.component
Decorators
• Decorators are functions that provide a declarative way to
add metadata to code
• Metadata tells Angular how to process a class
Lifecycle Hooks
• Implemented by components and directives
• Methods which are called when specific events
occur
• ngOnChanges() – called when data-bound input
properties are set/reset
• ngOnInit() – called shortly after the component is
created
• ngOnDestroy() – Called just before Angular destroys
the directive component
Lifecycle Hooks Example
app.componentlist.component
@Directive()
Directive is an attribute which can extend/modify the functionality of an element
• Target an element by its Selector – A CSS selector
• ‘[attributeToSelect]’
• ‘tag-to-select’
• ‘.class-to-select’
• Three Types
• Components - Directives with a template
• Structural Directives – Change the DOM layout by adding/removing DOM elements
• Attribute Directives – Change the appearance or behavior of an element
@Directive() Example
app.component hover-color.directive
@Component()
• A component is a directive with a template which contains logic for updating
or retrieving data to/from the view
@Component({
selector: ‘app-list’,
templateUrl: ‘./list.component.html’,
styleUrls: [‘./list.component.css’],
providers: [ListService]
})
export class ListComponent {}
Element to componentize
Path to View
Path to Styles
Component-
Scoped Services
@Component() Example
list.componentapp.component
@Pipe()
Pipes are used to transform data
• Two Types
• Pure – Only executed when a change is made to a primitive input value or a change
to an object reference
• Impure – Executed during every component change detection cycle
<p> {{ price | convertMoney : ’EUR’ : ’USD’ }} </p>
Object to
Transform
Pipe Name Argument 1 Argument 2
@Pipe() Example
app.component convert-money.pipe
@Injectable()
• Services are reusable classes which perform a specific task and are injected
using Angular 2’s hierarchical Dependency Injection system
• Constructor Injection
• Decorated with @Injectable() if any dependencies are required
• Singletons
• Domain scoped to Root Module or instance of Component
Root Module
Root DI Container
Component A
Instance Scoped DI Container
Component B
Instance Scoped DI Container
@Injectable() Example
app.component currency.service
@NgModule()
Helps organize application or library into cohesive blocks of functionality
• Declare what components, directives, and pipes (CDP’s) are used
• Provide services at the root module level
@NgModule({
imports: [FormsModule, CommonModule],
declarations: [ListComponent, HoverColorDirective],
exports: [ListComponent],
providers: [ListService]
})
export class CustomControlsModule {}
Modules used by any declared CDP’s, standalone
Declare any CDP’s used by this module
All modules which will exported and made available to the importing module
Any services used by the declared modules; Will be added to the root DI container
ASP.NET Core
ASP.NET Core Overview
• Built upon .NET Core, ASP.NET Core is a lean, cross-platform, open-source
framework for building web and cloud applications
• Supports C# and F#
• All Features/Libraries via NuGet packages (similar to NPM)
• Auto-Compiled Code
• Native Dependency Injection
• .NET Core and ASP.NET Core on Github
Dotnet Core Commands
• dotnet new
• creates a new project in the current directory
• dotnet restore
• installs the required NuGet packages
• dotnet run
• starts the application
• yo aspnet
• Options for scaffolding .NET Core apps
Components of ASP.NET Core
• Project.json
• Specify dependencies, configurations, frameworks
used and their versions
• Program.cs
• Application’s entry point
• Host is created and ran from here
• Startup.cs
• The configuration file for ASP.Net Core
• Inject services
• Configure services
Dependency Injection
Adds services to a container in order to achieve loose coupling between
objects and their dependencies
• Constructor Injection
• Service Types
• Transient
• Scoped
• Singleton
Public void ConfigureServices(IServiceCollection services) {
services.AddCors();
services.AddMvcCore().AddJsonFormatters();
services.AddScoped<PetService>();
services.AddSingleton<UtilityService>();
}
Public void Configure(IApplicationBuilder app, …) {
app.UseCors(cors => cors.WithOrigins(http://localhost:4200)
.AllowAnyHeader().AllowAnyMethod());
app.UseMvc();
}
Register Services
Use Services
Startup.cs
Controllers
Classes that handle browser requests and retrieves model data
[Route(“api/[controller]”)
public class PetsController : Controller {
private readonly PetService _petService;
public PetsController(PetService petService) {
_petService = petService;
}
[HttpGet(“{animalId}”)]
public List<Pet> Get(long animalId, bool isForSale = false) {
return _petService.GetPets(animalId: animalId, isForSale);
}
}
Route Template
http://myapp/api/pets
Constructor Injection
HTTP Verb
http://myapp/api/pets/4?isForSale=true
Inherit Controller base class
Query String Parameters

More Related Content

PPTX
Angular 2.0
Mallikarjuna G D
 
PDF
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
Edureka!
 
PPTX
Angular 4
Saurabh Juneja
 
PDF
AngularJS Basics
Nikita Shounewich
 
PDF
New in Spring Framework 5.0: Functional Web Framework
VMware Tanzu
 
PDF
Angular Weekend
Troy Miles
 
Angular 2.0
Mallikarjuna G D
 
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
Edureka!
 
Angular 4
Saurabh Juneja
 
AngularJS Basics
Nikita Shounewich
 
New in Spring Framework 5.0: Functional Web Framework
VMware Tanzu
 
Angular Weekend
Troy Miles
 

What's hot (20)

PPTX
Coordinating Micro-Services with Spring Cloud Contract
Omri Spector
 
PPTX
What’s expected in Spring 5
Gal Marder
 
PDF
CraftCamp for Students - Introduction to AngularJS
craftworkz
 
PPTX
Angularjs Basics
Jayantha Sirisena
 
PDF
Dynamic input tables lwc vs aura vs. visualforce
Mike Tetlow
 
PPTX
Single Page Applications with AngularJS 2.0
Sumanth Chinthagunta
 
PDF
What angular 13 will bring to the table
Moon Technolabs Pvt. Ltd.
 
PDF
Scala quick start
Sukjin Yun
 
PPTX
MuleSoft Meetup Warsaw Group DataWeave 2.0
Patryk Bandurski
 
PPTX
ASP.Net 5 and C# 6
Andy Butland
 
KEY
Everything you need to know about HTML5 in 15 min
Edgar Parada
 
PDF
Introduction to React, Flux, and Isomorphic Apps
Federico Torre
 
PPTX
Angular
khoado2002
 
PPTX
Reactive Micro Services with Java seminar
Gal Marder
 
PPTX
Effective .NET Core Unit Testing with SQLite and Dapper
Mike Melusky
 
PDF
Reactive Thinking in Java
Yakov Fain
 
PPTX
Step by step guide to create theme for liferay dxp 7
Azilen Technologies Pvt. Ltd.
 
PDF
Understanding Facebook's React.js
Federico Torre
 
ODP
Developing Microservices using Spring - Beginner's Guide
Mohanraj Thirumoorthy
 
PPTX
Seif_mike_gsoc_2014_cloudstack
seif_100
 
Coordinating Micro-Services with Spring Cloud Contract
Omri Spector
 
What’s expected in Spring 5
Gal Marder
 
CraftCamp for Students - Introduction to AngularJS
craftworkz
 
Angularjs Basics
Jayantha Sirisena
 
Dynamic input tables lwc vs aura vs. visualforce
Mike Tetlow
 
Single Page Applications with AngularJS 2.0
Sumanth Chinthagunta
 
What angular 13 will bring to the table
Moon Technolabs Pvt. Ltd.
 
Scala quick start
Sukjin Yun
 
MuleSoft Meetup Warsaw Group DataWeave 2.0
Patryk Bandurski
 
ASP.Net 5 and C# 6
Andy Butland
 
Everything you need to know about HTML5 in 15 min
Edgar Parada
 
Introduction to React, Flux, and Isomorphic Apps
Federico Torre
 
Angular
khoado2002
 
Reactive Micro Services with Java seminar
Gal Marder
 
Effective .NET Core Unit Testing with SQLite and Dapper
Mike Melusky
 
Reactive Thinking in Java
Yakov Fain
 
Step by step guide to create theme for liferay dxp 7
Azilen Technologies Pvt. Ltd.
 
Understanding Facebook's React.js
Federico Torre
 
Developing Microservices using Spring - Beginner's Guide
Mohanraj Thirumoorthy
 
Seif_mike_gsoc_2014_cloudstack
seif_100
 
Ad

Viewers also liked (20)

ODP
Embrace HTTP with ASP.NET Web API
Filip W
 
PDF
Modern angular 04_component_router
Manfred Steyer
 
PDF
Capitulo3
Jenifer Bautista
 
PPTX
Amit K Sawant C.V. - Presentation
Amit Sawant - MRICS
 
PDF
Bm 300 manual
leena leena
 
PPT
asp .net training | asp.net course | asp.net training online | learn asp.net
Nancy Thomas
 
PDF
Recent UX Success
Lou Susi
 
PDF
Building Native Experiences with Electron
Ben Gotow
 
PPTX
Ievadprezentacija, Latvijas vecāku forums 2016
BJPLC
 
PPTX
Building HTTP APIs with ASP.NET Core
Filip W
 
ODP
Unit207 slideshare cheryl_cripps_18.03.16
Cheryl Cripps
 
PDF
Cross-Platform Desktop Apps with Electron
David Neal
 
PDF
Cross-Platform Desktop Apps with Electron (CodeStock Edition)
David Neal
 
PPTX
Biografy designer grafis
sigitartstudio
 
PPSX
Electron - Build cross platform desktop apps
Priyaranjan Mohanty
 
PPTX
Asp.net orientation
Yogendra Tamang
 
PPTX
work and energy
Rks Ptl
 
PPTX
Ova001 Mixología Básica
Juanmendozaa
 
PDF
CoffeeScript com Visual Studio e ASP.NET MVC
Giovanni Bassi
 
PPTX
Angular, ASP.NET Core, and Visual Studio Code - Oh My!
Aaron Marisi
 
Embrace HTTP with ASP.NET Web API
Filip W
 
Modern angular 04_component_router
Manfred Steyer
 
Capitulo3
Jenifer Bautista
 
Amit K Sawant C.V. - Presentation
Amit Sawant - MRICS
 
Bm 300 manual
leena leena
 
asp .net training | asp.net course | asp.net training online | learn asp.net
Nancy Thomas
 
Recent UX Success
Lou Susi
 
Building Native Experiences with Electron
Ben Gotow
 
Ievadprezentacija, Latvijas vecāku forums 2016
BJPLC
 
Building HTTP APIs with ASP.NET Core
Filip W
 
Unit207 slideshare cheryl_cripps_18.03.16
Cheryl Cripps
 
Cross-Platform Desktop Apps with Electron
David Neal
 
Cross-Platform Desktop Apps with Electron (CodeStock Edition)
David Neal
 
Biografy designer grafis
sigitartstudio
 
Electron - Build cross platform desktop apps
Priyaranjan Mohanty
 
Asp.net orientation
Yogendra Tamang
 
work and energy
Rks Ptl
 
Ova001 Mixología Básica
Juanmendozaa
 
CoffeeScript com Visual Studio e ASP.NET MVC
Giovanni Bassi
 
Angular, ASP.NET Core, and Visual Studio Code - Oh My!
Aaron Marisi
 
Ad

Similar to Building Blocks of Angular 2 and ASP.NET Core (20)

PDF
better-apps-angular-2-day1.pdf and home
ChethanGowda886434
 
PPTX
Angular 2 in-1
GlobalLogic Ukraine
 
PDF
Angular Notes.pdf
sagarpal60
 
ODP
Angular2
kunalkumar376
 
PDF
Angular2 with type script
Ravi Mone
 
PPTX
Angularjs2 presentation
dharisk
 
PDF
Angular 2 overview in 60 minutes
Loiane Groner
 
PPTX
Angular Basics.pptx
AshokKumar616995
 
PDF
Building blocks of Angular
Knoldus Inc.
 
PPTX
Angular2 + rxjs
Christoffer Noring
 
PPTX
Angular 18 course for begineers and experienced
tejaswinimysoola
 
PPTX
Angularj2.0
Mallikarjuna G D
 
PPTX
Angular Framework ppt for beginners and advanced
Preetha Ganapathi
 
PPTX
Angular2 and You
Joseph Jorden
 
PPTX
Angular Course.pptx
Imdad Ullah
 
PPTX
Introduction to angular | Concepts and Environment setup
Ansley Rodrigues
 
PPTX
Angular crash course
Birhan Nega
 
PPTX
yrs of IT experience in enterprise programming
narasimhulum1623
 
PPT
17612235.ppt
yovixi5669
 
PPTX
Foster - Getting started with Angular
MukundSonaiya1
 
better-apps-angular-2-day1.pdf and home
ChethanGowda886434
 
Angular 2 in-1
GlobalLogic Ukraine
 
Angular Notes.pdf
sagarpal60
 
Angular2
kunalkumar376
 
Angular2 with type script
Ravi Mone
 
Angularjs2 presentation
dharisk
 
Angular 2 overview in 60 minutes
Loiane Groner
 
Angular Basics.pptx
AshokKumar616995
 
Building blocks of Angular
Knoldus Inc.
 
Angular2 + rxjs
Christoffer Noring
 
Angular 18 course for begineers and experienced
tejaswinimysoola
 
Angularj2.0
Mallikarjuna G D
 
Angular Framework ppt for beginners and advanced
Preetha Ganapathi
 
Angular2 and You
Joseph Jorden
 
Angular Course.pptx
Imdad Ullah
 
Introduction to angular | Concepts and Environment setup
Ansley Rodrigues
 
Angular crash course
Birhan Nega
 
yrs of IT experience in enterprise programming
narasimhulum1623
 
17612235.ppt
yovixi5669
 
Foster - Getting started with Angular
MukundSonaiya1
 

Recently uploaded (20)

PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PDF
Protecting the Digital World Cyber Securit
dnthakkar16
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PDF
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PDF
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
PDF
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
PPT
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
PPTX
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
PDF
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
PPTX
oapresentation.pptx
mehatdhavalrajubhai
 
PPTX
Explanation about Structures in C language.pptx
Veeral Rathod
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PPTX
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PPTX
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
PPTX
Presentation about variables and constant.pptx
kr2589474
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PDF
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
Protecting the Digital World Cyber Securit
dnthakkar16
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
Adobe Illustrator Crack Full Download (Latest Version 2025) Pre-Activated
imang66g
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
An Experience-Based Look at AI Lead Generation Pricing, Features & B2B Results
Thomas albart
 
Applitools Platform Pulse: What's New and What's Coming - July 2025
Applitools
 
Why Reliable Server Maintenance Service in New York is Crucial for Your Business
Sam Vohra
 
Web Testing.pptx528278vshbuqffqhhqiwnwuq
studylike474
 
Balancing Resource Capacity and Workloads with OnePlan – Avoid Overloading Te...
OnePlan Solutions
 
oapresentation.pptx
mehatdhavalrajubhai
 
Explanation about Structures in C language.pptx
Veeral Rathod
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
AI-Ready Handoff: Auto-Summaries & Draft Emails from MQL to Slack in One Flow
bbedford2
 
PFAS Reporting Requirements 2026 Are You Submission Ready Certivo.pptx
Certivo Inc
 
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
Presentation about variables and constant.pptx
kr2589474
 
Exploring AI Agents in Process Industries
amoreira6
 
vAdobe Premiere Pro 2025 (v25.2.3.004) Crack Pre-Activated Latest
imang66g
 

Building Blocks of Angular 2 and ASP.NET Core

  • 1. Building Blocks of Angular 2 and ASP.NET Core By Levi Fuller
  • 2. Overview • Angular CLI • Overview & Commands • Angular 2 • Overview • Template Binding • Decorators • Lifecycle Hooks • Directives • Components • Pipes • Injectables (Services) • Modules • ASP.NET Core • Overview • Commands / Files • Dependency Injection • Controllers • Pet Store Demo
  • 4. What is the Angular CLI? Provides a set of commands which enable you to: • Scaffold a new app • Scaffold the building blocks • Run the application • Build the application • Deploy it Scaffold Usage Component ng g component my-new-component Directive ng g directive my-new-directive Pipe ng g pipe my-new-pipe Service ng g service my-new-service Class ng g class my-new-class Interface ng g interface my-new-interface Enum ng g enum my-new-enum Module ng g module my-module
  • 5. NG2 with the Angular CLI • ng new <app-name> • Creates new directory and creates the app scaffolding inside the new directory • ng serve • Runs the application in memory via LiveReload server • ng build • Compiles the application and copies the output to the `dist` directory • ng github-pages:deploy • Builds the app, setups a GitHub repo, publishes to the GitHub page
  • 7. Angular 2 Overview Open source, front-end framework for developing Single Page Application (SPA’s) • Supports TypeScript, Dart, or JavaScript • Component-based architecture • Up to 5x faster than AngularJS pet- card.compo nent pet- card.compo nent pet.options app.component Browse-pets.component
  • 8. Data Binding Data binding is the mechanism for coordinating what users see with the component’s data values <input type=“text” value=“Levi”> {{person.name + ‘ is ’ + getAge(person.birthday)}} <input [value]=“person.name”> <input (input)=“name=$event.target.value”> <input [(ngModel)]=“name”> <input [ngModel]=“name” (ngModelChange)=“name=$event.target.value”> <input [value]=“name” (input)=“name=$event.target.value”> One-Time Initialization This is not data binding Event Binding One-Way from view to data source Two-Way Binding Property Binding + Event Binding Interpolation, Property, Attribute, Class, and Style Binding Data source to view One-WayTwo-Way
  • 10. Decorators • Decorators are functions that provide a declarative way to add metadata to code • Metadata tells Angular how to process a class
  • 11. Lifecycle Hooks • Implemented by components and directives • Methods which are called when specific events occur • ngOnChanges() – called when data-bound input properties are set/reset • ngOnInit() – called shortly after the component is created • ngOnDestroy() – Called just before Angular destroys the directive component
  • 13. @Directive() Directive is an attribute which can extend/modify the functionality of an element • Target an element by its Selector – A CSS selector • ‘[attributeToSelect]’ • ‘tag-to-select’ • ‘.class-to-select’ • Three Types • Components - Directives with a template • Structural Directives – Change the DOM layout by adding/removing DOM elements • Attribute Directives – Change the appearance or behavior of an element
  • 15. @Component() • A component is a directive with a template which contains logic for updating or retrieving data to/from the view @Component({ selector: ‘app-list’, templateUrl: ‘./list.component.html’, styleUrls: [‘./list.component.css’], providers: [ListService] }) export class ListComponent {} Element to componentize Path to View Path to Styles Component- Scoped Services
  • 17. @Pipe() Pipes are used to transform data • Two Types • Pure – Only executed when a change is made to a primitive input value or a change to an object reference • Impure – Executed during every component change detection cycle <p> {{ price | convertMoney : ’EUR’ : ’USD’ }} </p> Object to Transform Pipe Name Argument 1 Argument 2
  • 19. @Injectable() • Services are reusable classes which perform a specific task and are injected using Angular 2’s hierarchical Dependency Injection system • Constructor Injection • Decorated with @Injectable() if any dependencies are required • Singletons • Domain scoped to Root Module or instance of Component Root Module Root DI Container Component A Instance Scoped DI Container Component B Instance Scoped DI Container
  • 21. @NgModule() Helps organize application or library into cohesive blocks of functionality • Declare what components, directives, and pipes (CDP’s) are used • Provide services at the root module level @NgModule({ imports: [FormsModule, CommonModule], declarations: [ListComponent, HoverColorDirective], exports: [ListComponent], providers: [ListService] }) export class CustomControlsModule {} Modules used by any declared CDP’s, standalone Declare any CDP’s used by this module All modules which will exported and made available to the importing module Any services used by the declared modules; Will be added to the root DI container
  • 23. ASP.NET Core Overview • Built upon .NET Core, ASP.NET Core is a lean, cross-platform, open-source framework for building web and cloud applications • Supports C# and F# • All Features/Libraries via NuGet packages (similar to NPM) • Auto-Compiled Code • Native Dependency Injection • .NET Core and ASP.NET Core on Github
  • 24. Dotnet Core Commands • dotnet new • creates a new project in the current directory • dotnet restore • installs the required NuGet packages • dotnet run • starts the application • yo aspnet • Options for scaffolding .NET Core apps
  • 25. Components of ASP.NET Core • Project.json • Specify dependencies, configurations, frameworks used and their versions • Program.cs • Application’s entry point • Host is created and ran from here • Startup.cs • The configuration file for ASP.Net Core • Inject services • Configure services
  • 26. Dependency Injection Adds services to a container in order to achieve loose coupling between objects and their dependencies • Constructor Injection • Service Types • Transient • Scoped • Singleton Public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddMvcCore().AddJsonFormatters(); services.AddScoped<PetService>(); services.AddSingleton<UtilityService>(); } Public void Configure(IApplicationBuilder app, …) { app.UseCors(cors => cors.WithOrigins(http://localhost:4200) .AllowAnyHeader().AllowAnyMethod()); app.UseMvc(); } Register Services Use Services Startup.cs
  • 27. Controllers Classes that handle browser requests and retrieves model data [Route(“api/[controller]”) public class PetsController : Controller { private readonly PetService _petService; public PetsController(PetService petService) { _petService = petService; } [HttpGet(“{animalId}”)] public List<Pet> Get(long animalId, bool isForSale = false) { return _petService.GetPets(animalId: animalId, isForSale); } } Route Template http://myapp/api/pets Constructor Injection HTTP Verb http://myapp/api/pets/4?isForSale=true Inherit Controller base class Query String Parameters