Download presentation
Presentation is loading. Please wait.
1
.NET Framework 4 之旅 姓名 职务 公司
The .NET Framework 4 release will include several enhancements to the framework that make application development easier. In this session, you’ll look at several sample applications that demonstrate how this release of the framework makes development easier. You’ll look at the new Managed Extensibility Framework, changes to the CLR and C# and VB, improvements to data access, services and workflow technologies. You’ll also see how enhancements to ASP.NET and Windows Presentation Foundation make building end-user applications easier. 姓名 职务 公司
2
回顾…… SP1 3.5 3.0 .NET 1.0 .NET 1.1 .NET 2.0 .NET 4 2002 2003 2008 CTP CLR 1.0 CLR 1.1 CLR 2.0 CLR 4
3
基础类库(Base Class Libraries)
.NET Framework WPF Win Forms DLR ASP.NET WCF LINQ 更多! 基础类库(Base Class Libraries) CLR JIT & NGEN 垃圾 收集器 安全 模型 异常 处理 Loader & Binder
4
Web 应用程序 客户端应用程序 客户端/服务器 Web Forms 4 AJAX 4 WPF 4 MEF WCF 4
Big news about Web Forms 4 is that Dynamic Data will be rolled into Web Forms 4 so it’s not a separate “project”\”assembly”\etc. with .NET 4 客户端/服务器 WCF 4
5
构建块…… 并行计算 数据访问 运行时 任务并行库 并行 LINQ Entity Framework 4 Data Services 1.5
DLR Integration Type Equivalence In-Process SxS
6
Web Forms 4 – 客户端 ID 控制层次 得到的客户端 ID: ctl00 ctl00_HeaderForm
3) 下拉列表 (“States”) 得到的客户端 ID: ctl00 ctl00_HeaderForm ctl00_HeaderForm_States
7
Product/{name} -> Product.aspx
Web Forms 4 – 路由 ASP.NET 路由 路由: Product/{name} -> Product.aspx 请求: 产品/Bikes WebForms 页面 文件名: Product.aspx 路由值: Name = “Bikes” 响应
8
ASP.NET Web Forms 4 客户端 Id / 路由
11/7/2018 4:21 AM ASP.NET Web Forms 4 客户端 Id / 路由 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
9
AJAX 4 – 客户端模板 服务器端 (WebForms): 客户端
<ItemTemplate> <li><%# Eval("Name") %></li> </ItemTemplate> Estimated Time: 3 minutes In order to enable our ability to easily create dynamic UI and place the rendering process on the client, we need a way to define templates of markup that represent the UI we wish to create, and allow the runtime to instantiate them for us. This alleviates the need to write a bunch of DOM code or depend on server-rendering. If you’ve used WebForms before, you’re already familiar with the approach many of its server controls take. You have access to a set of properties that allow you to define arbitrary templates of content, complete with HTML, server controls, and data binding expressions. This model makes it very easy to create dynamic UI that is rendered server-side [Advance Animation]. ASP.NET AJAX 4.0 introduces the ability to define templates as well, but purely client-side. Now you can create the HTML markup you want to use for representing your template, complete with HTML and data binding expressions. In this example, we’ve created an unordered list template whose content is a list item whose content is the value of the Name property of the JSON object that is bound to it. The data binding expression resembles that of WPF. 客户端 <ul class="sys-template"> <li>{{ Name }}</li> </ul>
10
AJAX 4 - DataContext * DataContext 包括自动更改跟踪 ASMX WCF 数据 上下文 1. 请求
ADO.NET Data Services 数据 上下文 2. JSON 数据 Estimated Time: 2 minutes The DataContext control essentially provides a connection between your client application and the server. The server component can be represented by any JSON compatible service, such as ASMX, WCF, and ADO.NET Data Services. The DataContext handles requesting data from the server [Advance Animation], as well as retrieving the returned JSON data. On the client, any JSON objects that were retrieved via a DataContext are participating in change tracking [Advance Animation]. This means that you can go about making any modifications you need, and can then simply save changes back to the server via the DataContext [Advance Animation] without having to worry about determining what changes have occurred. ASP.NET MVC JsonResult 3. 修改数据 4. 保存数据 其他 * DataContext 包括自动更改跟踪
11
ASP.NET AJAX 4 客户端模板/ 数据上下文
11/7/2018 4:21 AM ASP.NET AJAX 4 客户端模板/ 数据上下文 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
12
WPF 4 数据网格 Ribbon 多点触摸 Windows 7 增强
13
托管扩展性框架? 托管扩展性框架(Managed Extensibility Framework,MEF) 是 .NET Framework 中的一个新库,支持更好的重用应用程序和组件。使用 MEF、.NET 应用程序可以从静态编译转变为动态组合 MESSAGING: New Library = just an assembly, a normal .dll, used by any .NET language Dynamically Composed = composition takes place at runtime and composition behavior differs depending on how it is configured.
14
开放/封闭原则 软件实体 对于扩展是开放的, 但是对于修改是封闭的
15
已知 vs. 未知 MESSAGING: Due to it’s declarative-based and discovery-enabled approach, MEF becomes very powerful to use in an application where it is being used to put together a bunch of potentially unknown parts into a working application. You might also think about this as a 3rd party extending your application. When you are compiling your application (long before you ship), you have absolutely no idea on what sorts of extensions might be built for your application into the future. That’s the power of extensible applications, they can be extended and used in ways the original authors perhaps didn’t expect, or didn’t have the time to do themselves. If you are concerned strictly with the “known” part of the equation (composing different software entities together that are all known at compile time), there are other solutions that are available today that are very powerful for this scenario: namely IoC containers (IoC = Inversion of Control). The Managed Extensibility Framework was designed primarily with the unknown aspect of extension in mind.
16
客户单应用程序 WPF 4 DataGrid / MEF
11/7/2018 4:21 AM 客户单应用程序 WPF 4 DataGrid / MEF © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
17
Entity Framework 4 Model-First POCO 延迟加载 外键
18
WF/WCF 4 的众多新功能 纯 XAML 工作流是新的默认值 扩展的基本活动库 简化的 WF 编程模型 支持参数、变量和表达式
WF、WCF 和 WPF 之间的统一模型 扩展的基本活动库 简化的 WF 编程模型 支持参数、变量和表达式 对 WCF 集成进行了大量改进 运行时和设计程序改进 WCF 的服务交付 通过 “Dublin“ 进行管理
19
ADO.NET Data Services 1.5 服务器增强 客户端增强 行计数 服务器端分页 Feed 支持良好 BLOB 流
WPF/SL 数据绑定
20
ADO.NET Data Services 行计数和服务器端分页
11/7/2018 4:21 AM ADO.NET Data Services 行计数和服务器端分页 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
21
并行计算计划(Parallel Computing Initiative)
让最聪明的开发人员解决业务问题,而不是并发问题。 MESSAGING: Today, concurrency usually has to be done by the brightest developers in a business. The problem with this is that the brightest developers are then being consumed by concurrency minutia rather than being able to be focused on core business problems and helping the business’s bottom line. By providing new libraries and tools that make it easy to write parallel code, we hope to allow the best and brightest developers focus on the business problems at hand. This in turn enables other developers to be able to address concurrency and parallelism. This is the long term goal of Microsoft with the Parallel Computing Initiative. Visual Studio 2010 and .NET Framework 4 is merely the first step being taken in this direction. “大众的并发”
22
.NET 4 的并行计算 任务并行库 (TPL) 并行 LINQ (PLINQ)
Coordination Data Structures (CDS) System.Threading 改进
23
并行 LINQ 并行 LINQ (PLINQ) 使开发人员能够轻松利用 manycore,并对现有 LINQ 编程模型产生最小的影响
var q = from p in people where p.Name == queryInfo.Name && p.State == queryInfo.State && p.Year >= yearStart && p.Year <= yearEnd orderby p.Year ascending select p; .AsParallel() MESSAGING: PLINQ is a technology that allows developers to _easily_ leverage manycore. The great thing about PLINQ is that if you are using LINQ-to-objects, there is a very minimal impact to your code in order for it to use PLINQ. All it takes to use PLINQ is adding “.AsParallel()” to your query. This will turn the query into a PLINQ query and will use the PLINQ execution engine when executed. One small change, and your code now takes advantage of all the hardware available to you. NOTES: AsParallel() works by returning an IParallelEnumerable so every subsequent query operator works against the new IParallelEnumerable rather than the normal IEnumerable. See the hands-on lab for Parallel Extensions for more details.
24
并行计算 并行 LINQ (PLINQ) 11/7/2018 4:21 AM
© 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
25
为什么选择 DLR? Ruby Python VB C# 通用语言运行时 动态类型 静态类型 MESSAGING:
There is a good reason why the Dynamic Language Runtime (DLR) exists. The problem is that, today, dynamically- typed languages like Python and Ruby can’t easily run directly on top of the CLR as the CLR is primarily designed for statically-typed languages. By creating the DLR, we help plug that hole and allow dynamically-typed languages to run on top of the CLR (by working through the DLR). VB C# 通用语言运行时
26
为什么选择 DLR? Ruby Python VB 动态语言运行时 C# 通用语言运行时 动态类型 静态类型 MESSAGING:
The DLR provides core services that are necessary for dynamically-typed languages to work on the CLR The DLR also provides other services that can be used by statically-typed languages as well to achieve more dynamic behavior: Expression Trees (including Statements) Dynamic Dispatch Call Site Caching VB 动态语言运行时 C# 通用语言运行时
27
.NET 动态编程 动态语言运行时 表达式树 动态分配 调用站点缓存 IronPython IronRuby C# VB.NET 其他…
MESSAGING: The power of the DLR is that there are many binders for the DLR. Yes, we can interop with dynamic languages like Python and Ruby like we expect to. However, perhaps even more importantly, there are binders available for .NET, Silverlight, and Office. This allows us to interact between these platforms in very powerful ways that we were unable to currently. Python Binder Ruby Binder Object Binder JScript Binder COM Binder
28
动态类型对象 静态类型也能动态 动态转换 动态方法调用 Calculator calc = GetCalculator();
int sum = calc.Add(10, 20); object calc = GetCalculator(); Type calcType = calc.GetType(); object res = calcType.InvokeMember("Add", BindingFlags.InvokeMethod, null, new object[] { 10, 20 }); int sum = Convert.ToInt32(res); MESSAGING: As long as we stay in our statically-typed world, interacting with objects is a pleasant and intuitive experience. However, as soon as you step out of that boundary and have to start using reflection, your code becomes much less elegant, harder to read, and harder to maintain. Using ScriptObject in the DLR makes this a bit easier as it provides some direct method calls to invoke methods with specific parameters. And while this is an improvement, it’s still a departure from the way we are used to interacting with objects. Using the new dynamic keyword in C# 4, we can call the .Add method above exactly as it were statically typed like in our first code snippet. In this case, the calc object is statically typed to be dynamic (yes, that’s true). Once we have a dynamic object references, we can dynamically invoke methods, do dynamic conversion, etc. ScriptObject calc = GetCalculator(); object res = calc.Invoke("Add", 10, 20); int sum = Convert.ToInt32(res); 静态类型也能动态 dynamic calc = GetCalculator(); int sum = calc.Add(10, 20); 动态转换 动态方法调用
29
11/7/2018 4:21 AM DLR 集成 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
30
Interop Assemblies 在托管代码和 COM 之间转换
类型等价物 Interop Assemblies 在托管代码和 COM 之间转换 每个接口、struct、enum、代理和数字都包含一个与 marshalling(聚合)数据等效的托管代码 MESSAGING: Office has thousands of APIs for addins exposed through COM. But COM was designed for native code. Interop Assemblies help “translate” between managed and native code by containing all the marshalling data necessary to make communication possible.
31
主要的 Interop Assemblies 带来了许多难题……
但是! 主要的 Interop Assemblies 带来了许多难题…… MESSAGING: Let’s look at Office as an example. Add-ins in Excel, for instance, may very well need to talk to each other -> Because they have to talk to each other, they have to be using the same types for Excel -> Because of the way the type system works in the CLR, these types must also be in the same assembly -> So, the assembly is required to be in a common location (e.g. the GAC) in order for the add-ins to function properly. Well, Office currently does not require the .NET Framework to be installed on a machine. If a machine doesn’t have .NET installed, there’s no GAC, and hence nothing to deploy the PIA into. Herein lies the problem. Even if an add-in is only using a single function, enum, etc. from the interop assembly, the add-in must deploy the entire PIA along with itself. Office PIA is around 10-20mb, it’s HUGE. So you might have a 100k add-in “bringing along” a 20mb PIA.
32
走开,PIA! 编译器嵌入附件实际使用的 interop assemblies 中 运行时确保这些类型的嵌入定义是经过深思熟虑的等价物
MESSAGING: There are two primary things that enable PIAs to be buried, forever, never to rise again. Compiler enhancements (this embedding works down to the method level even, so even a full interface is not required). Runtime enhancements Even though they are in different assemblies Even though they may have different subsets Hence, type equivalence allows two interfaces, enums, delegates and plain-old-data-structures to mark themselves as equivalent with each other.
33
11/7/2018 4:21 AM CLR 4 类型等价物 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
34
.NET Framework 兼容性 .NET 4.0 是高度兼容的版本 .NET 4.0 不会自动向前兼容
必须添加一个带有特定交换器的配置文件才能让 3.5 应用程序在 4.0 上运行。
35
等等……如果 4.0 兼容,为什么 3.5 应用程序不能自动在 4.0 上运行?
.NET Framework 兼容性 等等……如果 4.0 兼容,为什么 3.5 应用程序不能自动在 4.0 上运行? 最好的情况当然是在您构建应用程序所使用的框架版本上运行 联系 并提交您的应用程序进行测试!
36
Host Process (即 Outlook)
CLR 2 - 现有的 Side-By-Side .NET 2.0 2.0 附件 3.0 3.5 1.1 add-in .NET 1.1 MESSAGING: Side X Side releases solve app compat issue COM objects and other addins for different layers of the same cake can easily live together on the same runtime Highly compatible – but only certain kinds of functionality can be added Host Process (即 Outlook)
37
CLR 4 – 流程中的 Side-By-Side
2.0 附件 3.0 附件 3.5 附件 4.0 附件 3.5 .NET 4.0 3.0 MESSAGING: Run both 2.0-based and 4.0-based CLR in the same process Old components use old CLR New components use new CLR Configuration file and hosting APIs give you fine-grained control .NET 2.0 Host Process(即 Outlook)
38
问题?
39
11/7/2018 4:21 AM © 2008 Microsoft Corporation。保留所有权利。Microsoft、 Windows、Windows Vista 和其他产品名称是在美国和/或其他国家/地区的注册商标和/或商标。本 文档仅用于提供信息,并代表微软在本文档发布之时的看法。因为微软必须响应不断变化的市场需求,所以本文档不应视为微软的承诺,并且在 本文档发布之后,微软不保证所提供信息的准确性。微软对本文档中的信息不做任何明示或暗示的保证。、 © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Similar presentations