What’s new in .NET 4.5
We’re off.. a bit of a discussion about the history of the .Net Framework which is now 10 years old. The overview is fairly succinct. The presenters are quite relaxed, working off each other in a fluid fashion.
What are the key drivers for 4.5?
- Improve asynchronous functionality
- Windows 8 and Windows 8 RT
- NuGet and deployable packages
- A slimmer framework with NuGet packages
- User/community feedback
Showing the usage of asynch/await within the context of a WPF user interface. Much less code required than traditionally necessary, especially with regard to UI thread marshalling. Now we’re looking ‘under the hood’.
Naturally, using .Net Reflector. We’re reviewing the assembly. When using the asynch/await, the compiler generates a whole lot of code underneath. Bear this in mind when using asynch/await. It’s not ideal for small chatty applications.
Base I/O classes now support asynch – Stream/Text Reader/Writer etc. Moving on..
Review of the historic usages of IIdentity.. IPrincipal etc. Very basic capability, Basic role membership et cetera. Limited to roles only, lack of access to more information (e.g. e-mail address).
4.5 becomes more claims aware. New class ClaimsIdentity (implements IIdentity) which allows the usage of claims tokens in applications. There’s a number of helper methods to help navigate claims auth. Other Principals inherit from this class. Allows for multiple identifies. Backwards compatible for older apps.
Active Directory in Server 2012 can now export claims tokens.
Windows Identity Framework now built into .Net 4.5 (no separate install
Portable Class Libraries
Although I’m pretty sure this was introduced in .Net 4.0? Ah, it was separate from the base framework in 4.0. [Demo]
This support is built into Visual Studio projects. Avoid the need
for cross platform precompiler definitions as the compiler will pick up
- Profile optimization and multicore JIT
- Timeout for regex (probably not a bad idea)
- New namespace (new zip/compression support) guess the licensing issues are resolved?
- WeakReference – typing changes/in case an object gets disposed
- Nice: set internationalization (culture) into app domain (good for a few reasons)
All Things Web
- HTTP programming model (read: RESTful applications)
- Full support for routes (MVC?)
- Content negotiation
- Query composition (QueryString)
- Self hosted apps
Let’s find out more. Mahesh has the stage.
CRUD operations can be mapped to HTTP verb actions (GET, POST etc). HTTP programming support enhanced in .Net 4.5. Out of the box includes content negotiation. On the fly content filtering using WebAPI. Onto a [Demo]
Fiddler for the win! Mahesh is showing the HTTP request/response in real time. We’re seeing the raw JSON data in the response. Now, showing how the response can be changed to return basic XML. Out of the box functionality. Reference data to Mr. Philip Beadle (of DotNet Nuke fame).
Adding a controller adds the appropriate handling code. Needs to
have exception handling, but otherwise everything is hooked up.
The HTTPClient class can be used to programmatically instantiate a
HTTP client object. Very useful for executing get requests and
evaluating responses etc.
Polling has long been an approach for lookups. Can it be done better? Establish a connection with a normal call. Full duplex bi-directional communication. Built on HTTP, support for proxies. Supports binary, UTF-8.
Supported in IIS 8, ASP.net 4.5, WinRT and WCF4.5 and Win 8, Win Server 2012.
[Demo – Chat Application using Web Sockets]
Loving the page title ‘Cheap Chat Page’.
Message sent to server, server broadcasts to other users. A little underwhelming being local box and two users. Lets see the magic! Time to look at the code:
Http Handler checks the request, routes to a handler if the request
is a web socket request. Would like to see this fleshed out a bit more.
ASP.net Web Forms
- Strongly typed data controls (finally!)
- Improved asynch support (per the goals of the release)
- Minification of js/css (built in)
- Server controls updated to generate HTML 5
- Razor enhancements
- Changes to the template
- Asynch, asynch!
- Improved mobile support
Moving to a [Demo].. ASP.net. Data binding with strongly typed controls – bye bye, eval(). Demo shows validation, routing (no .aspx in the URL) and enhanced query string interpretation. Still registering routes in a way which won’t be new to MVC programmers.
Windows Workflow – he was pointing at me *grin*
- Easier to configure (finally!). Default values are now more sensible.
- Proxies define asynch methods by default!
- Can create explicit task based asynch operations
- Web Sockets (as previously mentioned) – requires NuGet package,
- Support for UDP protocols (datagrams!)
- Better exposed API control through code
- Uses a “Configure” operation to provide runtime code defined config
- WCF support for Windows 8 apps
[Demo – WCF and a Windows 8 App] Note: Using Entity Framework (nice).
Note that synch and asynch are in the generated client proxies.
Asynch methods were not enabled by default in the past. Windows 8
client doesn’t support synch operations – asynch only (due to
Metro/hanging UI thread). No config files for Windows 8 apps. Demo
- Ribbon control is now out of the box.
- Feel free to ribbon your own apps, mystify your users too! Just kidding.
- Validates data asynchronously
- Data binding has changed
- delay binding (due to asynch?)
- binds to static properties (yay!)
- Markup extensions for events
- C# expressions supported
- Contract-first workflow services
- Workflow versioning (finally!) out of the box (loads the correct workflow with activity)
- Dynamically update workflows/versioning
- Authoring and designer improvements (again.. finally!)
- Add comments, enhanced browsing
- Add comments, enhanced browsing
Other Cool Stuff (Part 2)
Moves closer to an IoC for mocking and dependency injection.
- Support for open generic parts
- Convention/rule based registration
- build rules for import/export without declarations/attributes
- Scoping enhancements
- Diagnostic improvements
- For Metro and web apps
Quick thought – anything on the runtime compiler (Roslyn?)?
The Task Parallel Library.. coming along nicely..
- Performance improvements
- New methods
- Progress<T> class
TPL Data Flow
Looking at reactive systems – in memory data flows, agent based controls. New .Net Library.
This is something I’m going to be very keen to have a play with. Keep an eye on Sanders Technology for more on the TPL/TPL Data Flow.
- Set of blocks (primitives)
- EG ActionBlock/TransformBlock/BufferBlock
Quick [Demo] of the new TPL Data Flow. We’re coming to a close shortly.
Not a minor release.. great support for Windows 8, Asynch, performance improvements. Let’s wrap it up there.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)