Slide 1

Slide 1 text

Angular 2 for .NET Developers Pawel Gerr Thinktecture AG @pawelgerr

Slide 2

Slide 2 text

Motivation Why should we look into Angular 2? Do we have to rethink everything we learned? Live Coding Testing Going Native Talking Points 2

Slide 3

Slide 3 text

• WPF (Windows Presentation Foundation) • UWP (Universal Windows Platform) runs on Windows 10+ only • Xamarin supports mobile devices basically (at the moment) What about WPF/ UWP / Xamarin? 3

Slide 4

Slide 4 text

Web applications are accessible on all devices in a browser … if we have access to the network • HTML, scripts and styles have to be downloaded • Unless we are using Application Cache that is deprecated • Service Workers whose specification isn’t finished yet • The views are rendered on the server, in general ASP.NET applications are usually not designed to run completely offline What about ASP.NET? 4

Slide 5

Slide 5 text

Fortunately, we don’t have to … Do we have to rethink everything we learned? 5

Slide 6

Slide 6 text

Macro Architecture 6 Server Web API STS API Controller (Facade) Business Logic Ressource / Data Access (EF) SQL Server MySQL Sqlite WS Files Angular + HTML + JS Browser Cordova iOS Android Electron Win MacOS Linux CefSharp .exe Win 8 & 10

Slide 7

Slide 7 text

MVVM (Model-View-ViewModel) Architectural Pattern – WPF 7

Slide 8

Slide 8 text

MVC (Model-View-Controller) Architectural Pattern – ASP.NET MVC 8

Slide 9

Slide 9 text

MVW (Model-View-WhatEver) Architectural Pattern – Angular 2 (SPA) 9

Slide 10

Slide 10 text

Compose desired user control Usage Components in WPF 10 Name:

Slide 11

Slide 11 text

Child Actions (MVC 5) or ViewComponents (MVC 6) Usage Component in ASP.NET 11 [ViewComponent] public class CustomerFormViewComponent : ViewComponent { public IViewComponentResult Invoke() { var customer = new CustomerViewModel() { Name = "Customer name"}; return View(customer); } } @using (Html.BeginForm()) { @Html.Label("Name:"); @Html.TextBoxFor(model => model.Name); } @Component.Invoke(typeof(CustomerFormViewComponent))

Slide 12

Slide 12 text

Create and export a component Usage Components in Angular 2 12 @Component({ selector: 'customer-form', template: ` Name: ` }) export class CustomerForm { public name: string; constructor() { this.name = 'Customer name'; } }

Slide 13

Slide 13 text

WPF • XAML ASP.NET MVC • HTML (Razor Engine) • Server-side rendering Angular 2 • HTML (Built-in Parser) • Client-side rendering by default • Open rendering architecture (can be done on server or in mobile native environments) Declarative View Definition 13

Slide 14

Slide 14 text

XAML • One-Way • Two-Way ASP.NET • One-Way • Two-Way not applicable because the rendering happens on server Angular 2 • One-Way • Two-Way Data Binding 14 @Html.TextBoxFor(model => model.Name) @Model.Name {{name}}

Slide 15

Slide 15 text

.NET • Yes, .NET offers compile-time type safety  • Razor markup is type safe as well Angular 2 • Uses TypeScript that is a typed superset of Javascript Type Safety 15 @Component({ … }) class CustomerForm { public name: string; constructor() { … } public submit(): void { … } }

Slide 16

Slide 16 text

.NET • Libraries: Ninject, AutoFac, Unity, … • Supports: Constructor/property/method injection Angular 2 • Build-in dependency injection • Supports: Constructor injection Loose Coupling via Dependency Injection 16

Slide 17

Slide 17 text

.NET • Unit and integration tests with the help of dependency injection • Libraries: MSTest, nUnit, Moq, FluentAssertions, … Angular 2 • Unit and end-to-end tests • Libraries: Jasmine, Karma, Instanbul, Protractor Testing 17 describe(‘getCustomers', () => { const service = new CustomerService(); it('should return 3 customers', () => { var list = service.getCustomers(); expect(list.length).toBe(3); }); });

Slide 18

Slide 18 text

Here are some tools you should look at • Package Manager: NuGet => NPM • Building Projects: MsBuild/„F6“ in Visual Studio => Gulp • [Optional] Testing: MsTest/nUnit etc. => jasmine and karma • [Optional] Debugger: Visual Studio => Chrome Dev-Tools • [Optional] IDE: Visual Studio => WebStorm Tooling 18

Slide 19

Slide 19 text

Setup and Bootstrapping Live Coding 19

Slide 20

Slide 20 text

• Hierarchical dependency injectors Live Coding – Dependency Injection 20

Slide 21

Slide 21 text

Pawel Gerr Thinktecture AG [email protected] @pawelgerr Contact 21

Slide 22

Slide 22 text

Angular 2 • https://angular.io • https://angular.io/docs/ts/latest/guide/ architecture.html Angular 2 – Unit Testing • https://medium.com/google-developer- experts/angular-2-unit-testing-with- jasmine-defe20421584#.gii2d4r29 Bootstrap • http://getbootstrap.com AdminLTE 2 • https://almsaeedstudio.com/themes/Ad minLTE/index2.html WebStorm • https://www.jetbrains.com/webstorm/speci als/webstorm/webstorm.html Cordova • http://cordova.apache.org/ Electron • http://electron.atom.io/ Gulp • http://gulpjs.com/ Demo App • https://github.com/PawelGerr/angular2- todolist/tree/usergroupevents Resources 22

Slide 23

Slide 23 text

Thank you. 23