I made a mistake recently and did my shortest posting ever – basically just a URL – talking about the newest features in ASP.NET 5. Time to explore this in a little more detail. I’m still wading through what I think about ASP.NET 5 from a programming standpoint, so give me time and patience. I also stole liberally a lot of the slide pix below from Channel9, which I’m crediting in the footnotes. Sorry I’m just not that good of a graphics artist guys!
ASP.NET 5 Design Goals
Remember this compilation process?
Here’s the design goals that I see with ASP.NET 5:
- No more assembly refs, manage all in NuGet or edit project.json directly. (example, in project.json search Microsoft.AspNet..Http to show Intellisense) – can edit with text editor
- Unified programming model that combines MVC, Web API, and Web Pages
- Used to have things like System.Web.Http.Routing and System.Web.MVC.Routing. Combining them simplifies runtime significantly. Web Pages, WebAPI and MVC all MVC6. (note, web pages come later)
- Ability to self-host or host on IIS
- Side-by-side versioning of the .NET Framework
- New tools in Visual Studio 2015
Smooth and Powerful
- New modular HTTP request pipeline. New pipeline is modular. Not a massive block – can pick and choose so it’s lean. Apps run noticeably faster.
- Cloud-ready environment configuration
- Ability to see changes without re-building the project using Roslyn compiler (viewbag.Message = “Changed code here”; in controller logic for About
- Open Source and Inclusive
New flexible and cross-platform runtime (full, core, cross-platform)
- – full is std, Core is cloud-optimized runtime, cross-platform means future Linux/Mac. Right now you’d use Mono for mac .NET dev.
Open source in GitHub
- Nothing hidden. Can watch code as it is written, submit extensions yourself. GitHub code repositories are used for all ASP.NET 5 development across the board.
Just for example, look at the duplication below with the three silos we used to have with three unevenly joined frameworks – WebForms, MVC, and WebAPI:
From Web Pages -> MVC -> WebAPI, lots of common elements. HTML Helpers in both Web Pages and MVC. Controllers, Actions, Filters, Model Bidning, DI from MVC to Web API. This meant LOTS and lots of redundancy. Attribute routing is a classic example – two separate implementations. One model now for model, binding, DI – all in common. And they really thought about DI first in this new model.
A New Way of Working as a Developer with Roslyn
One DI abstraction that the framework leverages. It’s minimalistic, by design. Pop in your own framework to handle IOC. And one note on authentication – tokens not yet migrated. Katana was our first stop, but OWIN very in your face. Now with vNext moving more to middleware handling of authentication. If you want the bits, the code is at www.asp.net/vnext, and nightly build is at github.com/aspnet/home.
The biggest change in my mind is the new config system – big focus is on moving seamlessly from on-premise to cloud. Big frustration in the past was, you’d configure locally it’d work great, move to cloud and it would blow up. This is an environment-based config system that understands what needs to be enabled based on key/value pairs. Note, all of NuGet packages are in the root, under packages folder. Look at the References node – there are all the dependencies. Browse thru it – ok, MVC depends on Razor, which …. Etc.
And you won’t see any system.web in this app at all! New config system is called out – so you can put name/value pairs for environmental variables (DEV, QA, PROD) iand the config system will pick up the value. Browse through startup.cs – see how it sets up EF, DI, ASP.Net Identity, and MVC. See the mvc routing set up at the bottom.
One of the biggest changes is – you don’t have to do a build, wait… no you modify controller code and hit F5. Try this – comment everything out. Then add an app.UseWelcomePage(); line at the end. Try it again with app.Run(async req => await req.Response.WriteAsync(“bfsfdldaf”));
So get in the habit of doing Edit, Save, F5. This to me was a huge improvement that I didn’t know I need it.
One change in naming conventions with MVC – you used to have to inherit from controller i.e. MyConttrolllerName : Controller. Now you can just declare a class. As long as it has the word Controller at the end, you’re good.
The package publishing is also smoother. Try to publish to a file folder locally. Should be fully self-contained. Could take this on a thumbdrive and pop onto a machine WITHOUT IIS. (Still recommend IIS)
I also dig the .NET compatability profiler. For my customers, this really will hit the mark:
Bower, Grunt and Gulp Integration
- Bower – manages client-side packages like Javascriopt/CSS libraries. http://bower.io/
- Grunt, Gulp are JS-based task runners (which automates routine dev tasks like minification, compilation, unit testing, linting, etc). ASP.NET 5.0 uses Grunt. See this link – note the superior way of handling dependencies to previous versions of .NET. http://gruntjs.com/getting-started
- Npm – is a packg manager. Bundled with all of the above.
For more on this, and a complete walkthrough, check out http://www.asp.net/vnext/overview/aspnet-vnext/grunt-and-bower-in-visual-studio-2015
Some link candy for you first to set the stage.
- Another great video on why this is a good move – http://channel9.msdn.com/Events/dotnetConf/2014/MVC-6
- What’s the big deal about dependency injection? http://blogs.msdn.com/b/webdev/archive/2014/06/17/dependency-injection-in-asp-net-vnext.aspx
- Samples including starter point and documentation: https://github.com/aspnet/home
- I love this walkthrough/overview: http://channel9.msdn.com/Events/dotnetConf/2014/MVC-6
Note some big changes above to deployments and EF migrations. Finally, Microsoft listened and is going Code-First versus the former unworkable and fragile EDMX design pane, where you would drag entities onto a window. This is MUCH more workable and extensible than EF5 shtuff. As a developer, I wouldn’t even mess with anything else. A few simple command line entries:
… and running these commands shows you the migration code you’d be using – for example the model snapshot and migration class. This sets up your entities (no more EDMX files!)
And ASP.NET MVC 6 now supports injection into a view from a class. See this link – http://www.asp.net/vnext/overview/aspnet-vnext/vc
And a little more on dependency injection – http://blogs.msdn.com/b/webdev/archive/2014/06/17/dependency-injection-in-asp-net-vnext.aspx
For a WebAPI walkthrough by the EXCELLENT Mike Wasson, see this link: http://www.asp.net/vnext/overview/aspnet-vnext/create-a-web-api-with-mvc-6