Building Modern Web Applications with ASP.NET...

23
Building Modern Web Applications with ASP.NET 5 Brij Bhushan Mishra

Transcript of Building Modern Web Applications with ASP.NET...

Page 1: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

Building Modern Web Applications with ASP.NET 5

Brij Bhushan Mishra

Page 2: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

Agenda

• Introduction

• Middleware

• Dependency Injection

• Configuration

• View Component

• QnA

Page 3: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

About Me

Brij Bhushan Mishra- Microsoft MVP - ASP.NET/IIS (4 Times)

- Architect/Consultant

- Blogger/Author

- http://codewala.net

- @code_wala

- [email protected]

Page 4: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

ASP.NET 5 – the key drivers

• Agility

• Productivity

• Performance

• Cloud

• Hybrid

Page 5: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

ASP.NET 5

Page 6: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

Hello ASP.NET 5

Demo

Page 7: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

Where is my HTTP Pipeline?

Page 8: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

HTTP Pipeline

HTTPModule 1

HTTPModule 2

HTTPModule 3

HTTPModule n

HTTP Handler

Request Response

.

.

.

1• Application_BeginRequest

2• Application_AuthenticateRequest

3• Application_AuthorizeRequest

7• Application_PreRequestHandlerExecute

8•Handler executes the request

9•Application_PostRequestHandlerExecute

10• Application_ReleaseRequestCache

11• Application_UpdateRequestCache

12• Application_EndRequest

1• Application_BeginRequest

2• Application_AuthenticateRequest

3• Application_AuthorizeRequest

Page 9: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

OWIN

OWIN defines a standard interface between .NET

web servers and web applications. The goal of the

OWIN interface is to decouple server and

application, encourage the development of simple

modules for .NET web development, and, by being

an open standard, stimulate the open source

ecosystem of .NET web development tools

Page 10: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

Middleware

Pass through components that form a pipeline between a server and application to inspect, route, or modify request and response messages for a specific purpose.

It’s same as a HTTP Module

Page 11: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

Middleware

Processes the HTTPContext items

HTTPContext

_next

_next(httpcontext)_next(httpcontext)

Page 12: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

Middleware Chaining

Middleware1 Middleware2 Middleware3 Middleware4

Request

Response

Page 13: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

Let’s add some middlewares

Demo

Page 14: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

Dependency Injection

Page 15: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

Dependency Injection

Dependency Inversion Principle

Inversion of Control (IOC)

Service Locator (SL)Dependency Injection

Page 16: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

How?

• Startup class has one more method to inject the dependencies.

• These can be injected via property or constructor in any component.

• ConfigureServices

– Instance

– Transient

– Scoped

– Singleton

Page 17: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

Time to inject dependencies

Demo

Page 18: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

Where are Config files

Page 19: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

Where are configuration files

Earlier

• *.config files at different levels

• System.Configuration namespace to play with configfiles

Now

• These are not supported

• Lightweight that works on Cloud

• Different configuration in different environment

Page 20: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

What we get

• Light-weight

• Should work same everywhere, cloud optimized

• Have different configuration instance for different sub system like Identity, MVC, Razor

• Able to load configuration from diff sources

• Instantiated and Initialized in application itself

• Supports

– Json, xml,ini, environment variables, command line

Page 21: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

Add entry in Config

Demo

Page 22: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan

View Component

• A simple replacement for child actions

• Can be used instead Partial Views as well

• Easy separation of concerns and testable

• Provide the power of async

• Contains two parts

– A class that inherits from ViewComponent

– A razor view which call VC method

Page 23: Building Modern Web Applications with ASP.NET 5developermarch.com/developersummit/2015/report/download... · 2015-04-29 · Building Modern Web Applications with ASP.NET 5 Brij Bhushan