overview of .net framework - download.microsoft.com · presentation asp.net (webforms, mvc, dynamic...

32
Sanjay Vyas

Upload: others

Post on 24-Jun-2020

31 views

Category:

Documents


0 download

TRANSCRIPT

Page 2: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

.NET Framework 4.0

Network support and managed

services

Page 3: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

.NET Framework Current "Layer Cake"

.NET Framework 2.0 + SP1

Windows Presentation Foundation

Windows Communication

Foundation

Windows Workflow Foundation

Windows CardSpace

.NET Framework 3.0 + SP1

.NET Framework 3.5

LINQWF & WCF

Enhancements

Add-in Framework

Additional Enhancements

.NET Framework 3.5 + SP1

MVC Dynamic Data Entity Framework Data Services

Page 4: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Core

Services

.NET Framework 4.0

Base Class Library

Common Language Runtime

Windows Workflow

Foundation

Managed Extensibility Framework

Data ServicesWindows

Communication Foundation

“Velocity”

User Interface

Windows Presentation Foundation

ASP.NET(WebForms, MVC,

Dynamic Data)

Data Access

Entity Framework

LINQ

ADO.NET

Parallel Extensions

WinForms LINQ to SQL

LanguagesDynamic Language

Runtime

Page 5: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Whats New In Base Class Library

•Declaration & consumption of extensibility points

•Monitoring for new runtime extension

Managed Extensibility Framework

•BigInteger

•ComplexNumber

•Tuple

•SortedSet

New Data Types

•Memory Mapped Files

•Unified Cancelling Model

I/O Improvements

Page 6: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Managed Extensibility Framework

Create reusable components

Don’t we already have reusable components?No need to create infrastructure from scratch

MEF is dynamically composed

What’s so dynamic about itCurrent plugin model tied to specific apps

Same component cannot be used across apps

Discoverable at runtime

Tagging for rich queries and filtering

Page 7: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

MEF Architecture

Page 8: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

MEF

CatalogDiscovers and maintain extensions

CompositionContainerCoordinate creations and satisfy dependencies

ComposablePartOffer on or more exports

May depend on imports for extension it uses

Page 9: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Managed Extensibiity Framework

Page 10: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

New Language Features

C# 4.0Named Parameters

Optional Parameters

Dynamic Scoping

Generic Variance

Extension Property

VB.NET 10

Statement Lambdas

Multiline Lambdas

Auto implemented Properties

Collection Initializ er

Generic Variance

Extension Property

Page 11: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Optional and Named Parameter

Some methods have excessive parameters

Too many overloads of methods

Most aren’t used in everyday scenario

Developers still have to supply default values

Heavy use of Type.Missing

Comma counting is a pain

Difficult to remember parameter by position

Page 12: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Overload Of Overloads

class Book{

// Multiple constructorsBook() : this(“”, “”, “”, ){}

Book(string isbn) : this(isbn, “”, “”, 0){}

Book(string isbn, string title) : this(isbn, title, “”, 0){}

Book(string isbn, string title, string author) : this(isbn, title, author, 0){}

// Master Constructor which gets called by othersBook(string isbn, string title, string author, int pages){

// Do the actual work here}

}

Page 13: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Optional Parameters

class Book{

// Use optional parametersBook(string isbn=“”, string title=“”, string author=“”, int pages=0){

// Do the actual work here}

}

:::Book book = new Book(“1-43254-333-1”);Book book = new Book(“1-43254-333-1”, “How not to code”);Book book = new Book(“1-43254-333-1”, “How not to code”, “Copy Paster”);Book book = new Book(“1-43254-333-1”, 240); // Cannot skip parameters

Page 14: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Named Parameter

class Book{

// Use optional parametersBook(string isbn=“”, string title=“”, string author=“”, int pages=0){

// Do the actual work here}

}

:::Book book = new Book(isbn:“1-43254-333-1”);Book book = new Book(isbn:“1-43254-333-1”, title:“How not to code”);Book book = new Book(isbn:“1-43254-333-1”, title:“How not to code”, author:“Copy Paster”);Book book = new Book(isbn:“1-43254-333-1”, pages:240);

Page 15: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Dynamic scoping

C# is static type languagesTypes are explicitly defined

Methods are bound at runtime

Dynamic dispatch existsReflection API

Method.Invoke() is tedious

COM Automation is based on IDispatchMay not have .TLB

Lookup can be purely runtime

Certain Application Types require DynamismE.g. SOAP/REST proxies

Page 16: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Dynamic in .NET 4.0

CLR is mostly static typeCompile time type checking (e.g. IUnknown)

DLR added dynamism to .NETRun time type checking (e.g. IDispatch)

DLR is now part of .NET 4.0 APIFull support of IronRuby, IronPython

Dynamic dispatch now built into .NET/C#

Page 17: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ
Page 18: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Dynamic Dispatch

Introduction of type – dynamicCompiler merely packages information

Compiler defers binding to runtime

Built-in support for COM CallsUses IDispatch interface

PIA not required

Runtime binding for framework objects

Build your own – IDynamicObjectIronPython, IronRuby use this

E.g. RestProxy

Page 19: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Dynamic Data Type

Isnt Object type dynamic already?

.NET already has var, why add dynamic?

Object – Static type, base class

var – is ALSO static type, compiler inferred

dynamic – Evaluation deferred

Page 20: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Dynamic implementation

dynamic d = GetFlyingObject(“Superman”);d.Fly(); // Up, up and away

dynamic d = GetFlyingObject(“AirPlane”);d.Fly(); // Take off

dynamic d = GetFlyingObject(“Cat”);d.Fly(); // OOPS… but at runtime

Page 21: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Dynamic Dispatch

Page 22: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Variance

CovarianceSimilar to base reference to derived class

Covariance is applied to arrays, delegates..

ContravarianceSimilar to derived instance passed to base

Page 23: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Changes to Variance

Variance can now be applied to InterfacesVariant types supports interfaces and delegates

Variance applies to reference conversion only

Value types are not supported

CovarianceRequires the use of “out” keyword

ContravariantRequires the use of “in” keyword

It could be automatically inferred but that could lead to code-breaking when interface definition changes

Page 25: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Code Contracts

FoundationDesign by contract

Based on MSR’s SPEC#

What does it bring?Improved testability

Static verification

API Documentation

How does it help?Guarantee obligations on entry (parameter validations)

Guarantee property at exit (return value range)

Maintain property during execution (object invariance)

Page 26: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Code Contracts

New namespace in .NETSystem.Diagnostics.Contracts

Parameter validationContract.Requires()

Return value guaranteeContract.Ensures()

Object state guaranteeContract.Invariant()

Page 27: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Code Contracts

Compile generates the IL code

Contracts are conditionally compiled

Define CONTRACTS_FULL to enable

Page 29: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Parallelism in .NET 4.0

Don’t we have multithreading and ThreadPool?Requires too much work

Requires understanding of nitty-gritties

Bifurcated thinking for single CPU vs. multi

What does parallelism bring in?Make multicore programming simple

Automatcially handle single vs. multicore

Focus on “what” rather than “how”

Page 30: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Parallels in .NET

Task Parallel Library (TPL)Task and Data Parallelism

LINQ to Parallel (PLINQ)Use LINQ to implement parallelism on queries

Coordinated Data StructuresHigh performance collection classes which are lock free and thread safe

Parallel Diagnostic ToolsParallels Debugger and VSTS Profiler concurrency view

Page 31: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Task Parallel Library

Write code which automatically uses multicore

Expose potential parallelism in sequential code

No language extension (aka Syntactic sugar) yet

Parallelism typesThe Task Class – Task Parallelism

The Parallel Class – Data Parallelism

Task ManagementTaskManager class

Use default or create your own

Page 32: Overview of .NET Framework - download.microsoft.com · Presentation ASP.NET (WebForms, MVC, Dynamic Data) Data Access Entity Framework LINQ ADO.NET Parallel Extensions WinForms LINQ

Task Parallel Library