Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

ASP.NET Core 1 for MVC- and WebAPI-Devs

498 views

Published on

ASP.NET Core 1 for MVC- and WebAPI-Devs

Published in: Internet
  • Be the first to comment

  • Be the first to like this

ASP.NET Core 1 for MVC- and WebAPI-Devs

  1. 1. 1 ASP.NET Core 1 (formerly ASP.NET 5) What has changed for MVC and Web API devs? Manfred Steyer ManfredSteyer About me …  Manfred Steyer  SOFTWAREarchitekt.at  Trainer & Consultant  Angular  Server-Side .NET Page  2
  2. 2. 2 Goal Overview of changes for MVC- and Web API-Devs regarding ASP.NET Core Folie 3 Didactics Slides Samples Folie 9
  3. 3. 3 Contents Overview of ASP.NET Core 1 Bootstrapping Web Apps Web APIs Folie 11 OVERVIEW OF ASP.NET CORE Page  22
  4. 4. 4 .NET Core Folie 24 [http://www.hanselman.com/] Advantages Folie 25 X-Plattform Lightweight NuGet Side-by- Side Self-Hosting F5-Compile- to-Memory
  5. 5. 5 Hosting Kestrel (X-Plattform, Self-Host) WebListener (Windows, Self-Host) IIS  Kestrel Nginx  Kestrel Folie 26 Why a new ASP.NET? Folie 27 ASP.NET Frameworks System.Web IIS
  6. 6. 6 System.Web Features of System.Web have to be reimplemented Sessions, Caching, Configuration, Routing Consequence: Breaking-Changes Folie 30 Doublings today Web API MVC Web Pages
  7. 7. 7 ASP.NET MVC Core 1 Unification of MVC, Web API and (in future) Web Pages Uniform concepts for Controllers, Views, Dependency-Injection, Routing, Filters etc. Migration Code needs adaptation But: Current framework-versions will be maintained Saying that: WCF and Web Forms wont't be migrated to Core WCF Web Forms Web API 2MVC 5 .NET 4.x / "Full CLR"
  8. 8. 8 ASP.NET CORE 1: BOOTSTRAPPING Page  34 Middleware-Components Folie 35 Server Web-Framework Web-Application Middleware1 Middleware2 Middleware… Middlewaren Request Response Host-Process HTTP
  9. 9. 9 Configuring the Pipeline Folie 36 public class Startup { […] public void Configure(IApplicationBuilder app) { […] app.UseStaticFiles(); app.UseMvc(); […] } } Configuration considering the Environment Folie 37 public void Configure(IApplicationBuilder app, IHostingEnvironment env) { […] if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } […] }
  10. 10. 10 Configuring Services Folie 38 public class Startup { public void ConfigureServices(IServiceCollection services) { […] services.AddMvc() […] } […] } DEMO Page  40
  11. 11. 11 TAG-HELPER Page  45 @model IEnumerable<MvcApplication.Models.Flight> […] @foreach (var item in Model) { <tr> <td> @item.Von </td> <td> @item.Nach </td> <td> @Html.ActionLink( "Edit", "Edit", "Home", new { id = "1" }, null) </td> </tr> } HtmlHelpers in ASP.NET MVC 5
  12. 12. 12 @model IEnumerable<MvcApplication.Models.Flight> […] @foreach (var item in Model) { <tr> <td> @item.Von </td> <td> @item.Nach </td> <td> <a asp-controller="Home" asp-action="Edit" asp-route-id="1" class="navbar-brand">Edit</a> </td> </tr> } Tag-Helpers Using TagHelpers  @addTagHelper "*, Microsoft.AspNetCore.Mvc.TagHelpers" Global: Views/_ViewImports.cshtml Folie 48
  13. 13. 13 WEB APIS WITH MVC CORE 1 Page  50 Web APIs in MVC Core 1 No own Routing for Web APIs Same concept as for MVC No Conventions for HTTP Verb, like GetAll()  GET, PostData()  POST Routing doesn't consider URL-Parameters to select an action-method But: WebApiCompatShim Folie 51
  14. 14. 14 Web API with Attribute-based Routes Folie 52 [Route("api/[controller]")] public class FlightController: Controller { [HttpGet("{id}")] public Flight GetById(int id) { […] } [HttpGet("byRoute")] public List<Flight> GetByRoute(string from, string to) { […] } [HttpPost] public void PostFlight([FromBody] Flight flight) { […] } } Web API with Attribute-based Routes Folie 53 [Route("api/[controller]")] public class FlightController: Controller { // GET api/flight/{id} [HttpGet("{id}")] public Flight GetById(int id) { […] } [HttpGet("byRoute")] public List<Flight> GetByRoute(string from, string to) { […] } [HttpPost] public void PostFlight([FromBody] Flight flight) { […] } }
  15. 15. 15 Web API with Attribute-based Routes Folie 54 [Route("api/[controller]")] public class FlightController: Controller { // GET api/flight/{id} [HttpGet("{id}")] public Flight GetById(int id) { […] } // GET api/flight/byRoute?from=...&to=... [HttpGet("byRoute")] public List<Flight> GetByRoute(string from, string to) { […] } [HttpPost] public void PostFlight([FromBody] Flight flight) { […] } } Web API with Attribute-based Routes Folie 55 [Route("api/[controller]")] public class FlightController: Controller { // GET api/flight/{id} [HttpGet("{id}")] public Flight GetById(int id) { […] } // GET api/flight/byRoute?from=...&to=... [HttpGet("byRoute")] public List<Flight> GetByRoute(string from, string to) { […] } // POST api/flight [HttpPost] public void PostFlight([FromBody] Flight flight) { […] } }
  16. 16. 16 DEMO Page  56 Configuring MVC and Formatters Folie 57 public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddMvc() .AddJsonOptions(options => { […] }) .AddMvcOptions(options => { […] }); } […] }
  17. 17. 17 XML-Formatter Package: Microsoft.AspNetCore.Mvc.Formatters.Xml  XmlDataContractSerializerInputFormatter  XmlDataContractSerializerOutputFormatter Folie 58 DEMO Page  59
  18. 18. 18 Summary Folie 80 X-Plattform F5-Compile Side-by-Side Self-Hosting DI, DI everywhere… Tag Helpers Summary Folie 81 Unification of MVC and Web API High-Level- APIs quite the same MVC-Style Routing Low-Level APIs reworked Current versions still maintained
  19. 19. 19 manfred.steyer@SOFTWAREarchitekt.at SOFTWAREarchitekt.at ManfredSteyer Contact

×