MVC6. Awesomeness is here!

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

INTRODUCTION TO ASP.NET MVC AND EXAMPLE WALKTHROUGH RAJAT ARYA EFECS - OIM DAWG – 4/21/2009 ASP.NET MVC.
Introduction to MVC Adding a View Page NTPCUG Tom Perkins, Ph.D.
The Future of Web WakeUpAndCode.com.
Evolutie vs Revolutie Chris de Kok Evolutie vs Revolutie.NET 2015.NET 4.6 ASP.NET 5 -> MVC 6 Visual Studio 2015 C# 6.0 Agenda.
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
Ori Calvo, 2010 “If people want to have maximum reach across *all* devices then HTML will provide the broadest reach” Scott Guthrie,
Pittsburgh Java User Group– Dec Java PureFaces: A JSF Framework Extension.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
WorkPlace Pro Utilities.
ASP.NET 5 Visual Studio 2015 Templates Bill Wolff Rob Keiser June 10, 2015.
GEMVC. The Setup Folders Views Value Objects (VOs) Custom Events Service CFCs Controller Model Application Main MXML.
1 CONFIDENTIAL.NET FEATURES OVERVIEW C# 6 ASP.NET 5 DNX PROJECT ASP.NET MVC 6 EF 7 A UGUST 4, 2015.
Introduction to MVC Controllers NTPCUG Tom Perkins, Ph.D.
ASP.NET MVC Architecture Layouts, Filters, Sections, Helpers, Partial Views, Areas… SoftUni Team Technical Trainers Software University
Separating the Interface from the Engine: Creating Custom Add-in Tasks for SAS Enterprise Guide ® Peter Eberhardt Fernwood Consulting Group Inc.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
What’s New in ASP.NET 5 (vNext)? SoftUni Team Technical Trainers Software University Lean.NET stack for building modern web apps.
Introduction  “M” “V” “C” stands for “MODEL” “VIEW” “CONTROLLER”. ASP.NET MVC is an architecture to develop ASP.NET web applications in a different manner.
MVC5 Identity & Security Mait Poska & Andres Käver, IT Kolledž 2014.
Virtual techdays INDIA │ 9-11 February 2011 SESSION TITLE Kamala Rajan S │ Technical Manager, Marlabs.
BIT 286: Web Applications ASP.Net MVC. Objectives Applied MVC overview Controllers Intro to Routing Views ‘Convention over configuration’ Layout files.
ASP.NET Core* 1.0 The Future of Web Apps Shahed Chowdhuri
ASP.NET 5 WHAT HAPPENED TO SESSION AND APPSETTINGS.
I18n - DateTime ASP.NET MVC. I18n DateTime – EF changes  In model classes, use attributes  DataType(DataType.DateTime)  DataType(DataType.Date)  DataType(DataType.Time)
1 Using MVC 6. MVC vs. ASP Web Forms Both run under ASP.NET Can coexist In Web Forms, browser requests page. xxx.aspx and xxx.aspx.cs on the server Page.
Creating Consistent Looking Websites
ASP.NET Core* in 2017 The Future of Web Apps Shahed Chowdhuri
Build and Learn ASP.NET Workshop.
JavaScript, Sixth Edition
Moving away from alert() Using innerHTML Using an empty div section
Thymeleaf and Spring Controllers
Introduction to .NET Florin Olariu
An introduction to ASP.Net with MVC Nischal S
Building production ready APIs with ASP.NET Core 2.0
Browser Routing Design Patterns in JS
Building Web Applications with Microsoft ASP
Building Web Applications with Microsoft ASP
Social Media And Global Computing Introduction to The MVC Pattern
ASP.NET Core 2.0 Fundamentals
Play Framework: Introduction
ASP.NET Core* 1.0 The Future of Web Apps Shahed Chowdhuri
Dependency Injection Andres Käver, IT College 2016/2017 Spring.
Review: Two Programming Paradigms
Lean .NET stack for building modern web apps
Building Web Applications with Microsoft ASP
Env. Model Implementation
Modern Front-End Web Development with Visual Studio
MVC in ASP.NET Core: The new kid on the block
Explore web development with Microsoft ASP.NET Core 1.0
Microsoft Build /11/2018 2:12 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
Building Modern Web Apps with ASP.NET MVC 6
Dive deep into ASP.NET Core 1.0
Explore web development with Microsoft ASP.NET Core 1.0
Introducing ASP.NET Core 1.0
DotnetConf 11/17/ :06 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE.
Should I Transition to .NET Core? Will it hurt?
Authorization in Asp.Net Core
Social Media And Global Computing Managing MVC with Custom Models
Lecture 12: Message passing The Environment Model
TechEd /22/2019 9:22 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks.
6.001 SICP Variations on a Scheme
How to organize and document your classes
RESTful Web Services.
Web API with Angular 2 Front End
C# - Razor Pages Db/Scaffolding/Async
Dependency Injection Mechanism
Chengyu Sun California State University, Los Angeles
ASP.NET Core Middleware Fundamentals
CSC 581: Mobile App Development
Presentation transcript:

MVC6. Awesomeness is here! ASP.NET MVC6 essentials and why it’s awesome. At long last! 2015-11-17

Author Piotr Kamiński Developer Working for PGS for 2+ years MVC6. Awesomeness is here! 2018-11-20

Agenda How to start? What has changed? What’s new to the actual MVC? What about the identity model and stuff? MVC6. Awesomeness is here! 2018-11-20

Previously app.UseMVC() MVC6. Awesomeness is here! 2018-11-20

1. How to start? MVC6. Awesomeness is here! 2018-11-20

Let’s get started File, new project... ...wait, what? 1. How to start? MVC6. Awesomeness is here! 2018-11-20

„Panta rhei” Solution structure was changed drasticaly 1. How to start? „Panta rhei” Solution structure was changed drasticaly Old components were replaced with new ones, i.e.: web.config global.json project.json *.json global.asax Startup.cs Build process was reworked MVC6. Awesomeness is here! 2018-11-20

What should I do? Hit F5... ...and it works, wow! 1. How to start? public class Startup { public void ConfigureServices( IServiceCollection services) } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear(); }); app.Run(async (context) => await context.Response.WriteAsync("Hello, Wolrd!"); public static void Main(string[] args) => WebApplication.Run<Startup>(args); MVC6. Awesomeness is here! 2018-11-20

1. How to start? Wow wow wow wow MVC6. Awesomeness is here! 2018-11-20

Did I see „public static void Main”? 1. How to start? Did I see „public static void Main”? Correct! Reworked model of application building You tell the application where the entry point is New approach: you get what you want Previously: you got everything out of the box and had to deal with it MVC6. Awesomeness is here! 2018-11-20

How do I get MVC? It’s easy  Install MVC package 1. How to start? How do I get MVC? public void ConfigureServices(IServiceCollection services) { services.AddMvc(); } public void Configure(IApplicationBuilder app, HostingEnvironment env, ILoggerFactory loggerFactory) app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear(); }); app.UseMvc(routes => routes .MapRoute("error", "Error/{statusCode}", new controller = "Error", action = "Index" }) .MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}"); It’s easy  Install MVC package Tell the app to use MVC service Tell the app to use MVC Middleware Ready, steady, go! MVC6. Awesomeness is here! 2018-11-20

Give me more MVC! V for View C for Controller 1. How to start? Give me more MVC! V for View C for Controller Not so many changes, right? <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>My app</title> <link rel="stylesheet" href="~/css/App.css" /> </head> <body> <div class="section"> <div class="wrapper wrapper--wide"> @RenderBody() </div> @RenderSection("scripts", required: false) </body> </html> public class HomeController : Controller { private readonly UserManager<User> userManager; public HomeController(UserManager<User> userManager) this.userManager = userManager; } public IActionResult Index() return View(); public IActionResult Users() MVC6. Awesomeness is here! 2018-11-20

1. How to start? Create new project Register services Add selected components Hit F5 MVC6. Awesomeness is here! 2018-11-20

2. What has changed? MVC6. Awesomeness is here! 2018-11-20

Breaking changes Use contract instead of concrete 2. What has changed? Breaking changes Use contract instead of concrete Task, async, await... No reference to System.Web No Request, HttpContext, Session, Application global static objects Tag helpers View components MVC6. Awesomeness is here! 2018-11-20

Friend of yours is DI Built-in dependency resolver 2. What has changed? Friend of yours is DI Built-in dependency resolver You can add dependency resolver of your choice public void ConfigureServices(IServiceCollection services) { services .AddIdentity<User, Role>(); services.AddMvc(); services.AddScoped<IUserRepository, UserRepository>(); services.AddTransient<IUserStore<User>, AppUserStore>(); services.AddTransient<IRoleStore<Role>, AppRoleStore>(); services.AddTransient<SignInManager<User>, AppSignInManager>(); services.AddTransient<UserManager<User>, AppUserManager>(); services.AddTransient<IQueryableUserStore<User>, AppUserStore>(); } MVC6. Awesomeness is here! 2018-11-20

2. What has changed? MVC6. Awesomeness is here! 2018-11-20

2. What has changed? No more statics Use abstraction instead of concrete Task, async, await MVC6. Awesomeness is here! 2018-11-20

3. What’s new to the actual MVC? MVC6. Awesomeness is here! 2018-11-20

Separation of concerns in frontend 3. What’s new to the actual MVC? Separation of concerns in frontend Support for modern front end tools Bower and NPM as standard tools for obtaining FE packages Gulp, Grunt as task runners for FE related operations No more BundleConfig.cs! MVC6. Awesomeness is here! 2018-11-20

Front end, so much front end... 3. What’s new to the actual MVC? Front end, so much front end... MVC6. Awesomeness is here! 2018-11-20

3. What’s new to the actual MVC? Tag helpers Alternative approach to bind model to view called Tag Helpers Uses standard, legit, HTML5 tags Get access to context Several built-in helpers, i.e.: anchor, input, label... Easy to create own one Notice: old Razor syntax works as well MVC6. Awesomeness is here! 2018-11-20

Tag helpers example M for Model (bound to View) 3. What’s new to the actual MVC? Tag helpers example @using System.Threading.Tasks @using AppRC.ViewModel @model RegisterViewModel <form class="box box--huge" asp-controller="Account" asp-action="Register" method="post" role="form"> <div asp-validation-summary="ValidationSummary.All" class="text-danger"></div> <alert class="mb" message="This is an alert!"></alert> <div> <div class="layout"> <div class="layout__item u-1/8"> <label class="delta" asp-for="Name"></label> </div> <div class="layout__item u-2/4"> <input class="delta--regular" type="text" asp-for="Name" /> <label class="delta" asp-for="Password"></label> <input class="delta--regular" type="password" asp-for="Password" /> <button type="submit" class="btn">Register</button> </form> M for Model (bound to View) MVC6. Awesomeness is here! 2018-11-20

Custom tag helper It’s easy to create own tag helper 3. What’s new to the actual MVC? Custom tag helper It’s easy to create own tag helper We are given context of whole helper! [HtmlTargetElement("alert")] public class CustomAlertTagHelper : TagHelper { [HtmlAttributeName("message")] public string Message { get; set; } public override void Process(TagHelperContext context, TagHelperOutput output) output.TagName = "div"; output.Attributes.Add("class", "danger"); output.Content.SetContent(Message); } MVC6. Awesomeness is here! 2018-11-20

3. What’s new to the actual MVC? View components More powerful than partial views as they have own, separate controller Can work as async (but you should have assumed it by this time) Can be invoked with many parameters from view Designed as a response for urge to have reusable component No longer new SomeFancyViewModel() in view, yay!  MVC6. Awesomeness is here! 2018-11-20

View components example 3. What’s new to the actual MVC? View components example public class RegisteredUsersViewComponent : ViewComponent { private readonly UserManager<User> userStore; public RegisteredUsersViewComponent(UserManager<User> userStore) this.userStore = userStore; } public IViewComponentResult Invoke(int limitTo) var users = this.userStore .Users.Take(limitTo).ToList(); return View(users); @model List<AppRC.Model.Authentication.User> @foreach (var user in Model) { <div> <span>@user.Name</span> </div> } MVC6. Awesomeness is here! 2018-11-20

Injecting service into a view 3. What’s new to the actual MVC? Injecting service into a view ASP.NET MVC 6 now supports injection into a view from a class Can be useful in some scenarios, i.e. translations @using AppRC.Services @inject ILocalization Localization <h2> @Localization.Translate("Hello, world!") </h2> MVC6. Awesomeness is here! 2018-11-20

3. What’s new to the actual MVC? New folder and files structure NPM, Bower, Gulp, Grunt Tag Helpers View components MVC6. Awesomeness is here! 2018-11-20

4. What about the identity model and stuff? MVC6. Awesomeness is here! 2018-11-20

Identity model No more Forms Authentication 4. What about the identity model and stuff Identity model No more Forms Authentication Identity was replaced with a new identity model Three separate stores Users store Roles store Claims store Implemented out of the box with EF Easy to implement on your own MVC6. Awesomeness is here! 2018-11-20

Identity model diagram 4. What about the identity model and stuff Identity model diagram Images source: http://www.asp.net/identity/overview/extensibility/ove rview-of-custom-storage-providers-for-aspnet- identity#architecture MVC6. Awesomeness is here! 2018-11-20

4. What about the identity model and stuff? No more Forms Authentication New identity model with separation of: authentication, authorization and roles MVC6. Awesomeness is here! 2018-11-20

Bonus: where is the Session? Additional features Bonus: where is the Session? If statics were removed, where is the session then? You have to tell your infrastructure that you do want the session First commit: 9 May 2014 services.AddCaching(); services.AddSession(); app.UseSession(); MVC6. Awesomeness is here! 2018-11-20

Bonus: CORS Used to be pain Additional features Bonus: CORS Used to be pain Now you add it in a similar way as the session: app.UseCors(builder => builder.WithOrigins("pgs-soft.com", "ipgs-soft.com").Build()); MVC6. Awesomeness is here! 2018-11-20

Demo MVC6. Awesomeness is here! 2018-11-20

Summary How to start? What has changed? What’s new to the actual MVC? What about the identity model and stuff? MVC6. Awesomeness is here! 2018-11-20