ãã¾ãã«ã MVC 6 ã¯å¤æ´ãå¤ãã®ã§ãæ¦è¦ãã¨ãããããµã¯ãã¨ã¾ã¨ãã¦ããããï¼
ASP.NET 5 ã RTM ã«ãªãã¾ã§ã¯ããã¾ã確å®æ å ±ã¿ããã«æ¸ããªãããã«ãã¦ããã®ã§ããããã½ã¼ã¹ã³ã¼ãèªã¿ã¤ã¤èª¿ã¹ãèªåç¨ã¡ã¢ã ã¨æã£ã¦ãã ããã*1
Release 6.0.0-beta1 · aspnet/Mvc · GitHub
ã¡ãªã¿ã«ç¾å¨ã¯ 6.0.0-beta1 ããªãªã¼ã¹ããã¦ãã¾ããVisual Studio 2015 ã«å ¥ã£ã¦ãã®ã 6.0.0-beta1 ã ã£ããã¨æãã¤ã¤ãæ´æ°å 容å¤ãããããï¼ã¨ããæãã
Unified Framework
ããã¾ã§ã¯ ASP.NET MVC / Web API / Web Pages ã¨ããããå¥ã®ãã¬ã¼ã ã¯ã¼ã¯ã¨ãã¦éçºãè¡ããã¦ãã¾ããããASP.NET vNext ã® MVC 6 㧠Web API 㨠Web Pages ãçµ±åãã1 ã¤ã®ãã¬ã¼ã ã¯ã¼ã¯ã¨ãã¦çã¾ãå¤ããã¾ããã
MVC / Web API ã§ã¢ãã«ãã¤ã³ãã¼ãªã©å¥ã ã«å®è£ ããã¦ããã®ã§ãã¡ã³ããã³ã¹ã³ã¹ãã大ããã£ããã¨ãæ³åã§ãã¾ããå©ç¨è å´ã¨ãã¦ã¯æåã«å·®ãçºçããã¨ããã®ãè¾ãé¨åã§ããããMVC 6 ã§ã¯ãããªå¿é ããå¿ è¦ã¯ãªããªãã¾ããããå®è£ çã«ã¯ MVC ã« Web API ã®æ©è½ã追å ãããããªå½¢ã«ãªãã¾ãã
Async
MVC 5 ã¾ã§ã¯éåæã®ãµãã¼ããã¢ã¯ã·ã§ã³ã®ã¿ã§ããªãéå®çã§ããããMVC 6 ãã㯠HTTP ãã¤ãã©ã¤ã³ããå ¨ã¦ã Task ã使ã£ãéåæã§å®è£ ããã¦ãã¾ãã
WinRT ã¨åãããã«åæã¡ã½ãããæä¾ãããªãã±ã¼ã¹ãå¤ããªã£ãã®ã§ãæ¢åã®ã½ã¼ã¹ããã®ãã¤ã°ã¬ã¼ã·ã§ã³ã§ä¸çªè¦å´ããé¨åã«ãªãã¨æãã¾ãããåæãå¼·å¶ããã¦ãã ActionFilter ã OWIN 風㫠Delegate ãç¹ãå½¢ã«ãªã£ããã¡ãªãããå¤ãã§ãã
public virtual async Task OnActionExecutionAsync( [NotNull] ActionExecutingContext context, [NotNull] ActionExecutionDelegate next) { OnActionExecuting(context); if (context.Result == null) { OnActionExecuted(await next()); } }https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Core/Filters/ActionFilterAttribute.cs
ä»ã«ã Razor çã« @await ã¨ãããã¼ã¯ã¼ãã追å ããã¦ããã¥ã¼å´ã§ãéåæã§å¦çã§ããããã«ãªãã¾ããããã㯠View Components ãå¼ã³åºãæã«ä½¿ãç¨ãããã§èãã¦ããã¹ããã¨ã
ééã£ã¦ã DB ã¨ã HTTP ã®å¦çãå ¥ãã¦ã¯ãããªãã
Dependency Injection
ããã¾ã§ã MVC 3 ãã IDependencyResolver ã追å ããã¦ãã³ã³ã¹ãã©ã¯ã¿ã¤ã³ã¸ã§ã¯ã·ã§ã³ãªã©ã¯ä½¿ããããã«ãªã£ã¦ãã¾ããããMicrosoft.Framework.DependencyInjection ã¨ããæ°ãã DI 層ã追å ããã¦ä½¿ãåæãåä¸ãã¾ããã
ã¨è¨ã£ã¦ããDI ã®å®è£ ã¨ãã¦ã¯ Unity ã StructureMap ãªã©ãé¸ã¶å½¢ã«ãªãã¾ãã
// This method gets called by the runtime. public void ConfigureServices(IServiceCollection services) { // Add EF services to the services container. services.AddEntityFramework(Configuration) .AddSqlServer() .AddDbContext<ApplicationDbContext>(); // Add Identity services to the services container. services.AddDefaultIdentity<ApplicationDbContext, ApplicationUser, IdentityRole>(Configuration); // Add MVC services to the services container. services.AddMvc(); // Uncomment the following line to add Web API servcies which makes it easier to port Web API 2 controllers. // You need to add Microsoft.AspNet.Mvc.WebApiCompatShim package to project.json // services.AddWebApiConventions(); }
Startup ã¯ã©ã¹ã® ConfigureServices ãã©ã³ã¿ã¤ã ããå¼ã°ããããã«ãªããããã§å©ç¨ããããµã¼ãã¹ã追å ãã¦ããå½¢ã«ãªãã¾ããã*2
MVC ã使ãå ´åã«ã¯ AddMvc ã¡ã½ãããå¼ã³åºãã¦ãé¢é£ãããµã¼ãã¹ã追å ããªãã¨ã¨ã©ã¼ã«ãªãã¾ããMVC 5 ãããæ´ã«ã¢ã¸ã¥ã©ã¼ãªè¨è¨ã«ãªã£ã¦ã¾ãã
Formatters / ModelBindings
MVC 6 ã§ã¯æ°ããæ¦å¿µã¨ã㦠Formatter ã追å ããã¾ãããMVC 5 ã§ã¯ ValueProviderFactory ãå®è£ ãããã¨ã§ãJSON ã XML ããã®ã¢ãã«ãã¤ã³ãã£ã³ã°ãå¯è½ã§ããããMVC 6 ã§ã¯ãã®ãããã®ä»çµã¿ã Formatters ã«ç½®ãæãããã¾ããã
Formatter ã«ã Input / Output ã® 2 種é¡ãåå¨ãã¦ãããValueProviderFactory ã«ç¸å½ããã®ã Input 㧠Output 㯠JsonResult ãªã©ã§ã·ãªã¢ã©ã¤ãºãããæã«ä½¿ããã¾ãã
https://github.com/aspnet/Mvc/tree/dev/src/Microsoft.AspNet.Mvc.Core/Formatters
Web API ã® Media Type å¤å¥å¨ãã®å®è£ ã MVC ã«æã£ã¦ããã¨ããæãã§ããJson ã XML ç¨ã® Formatter ã¯ããã©ã«ãå®è£ ã¯ããã¾ããããã以å¤ã®ãã¤ããªç³»ã®ãã©ã¼ãããã使ãå ´åã«ã¯ç°¡åã«è¿½å ã§ããä»çµã¿ã«ãªã£ã¦ã¾ãã
POCO Controllers
ããã¾ã§ã¯ Controller ã¯ã©ã¹ãç¶æ¿ããå¿ è¦ãããã¾ããããMVC 6 ã§ã¯ DI ã使ã£ã¦ POCO ãªã³ã³ããã¼ã©ã¼ãå®è£ ã§ããããã«ãªãã¾ãããããããã£ã¤ã³ã¸ã§ã¯ã·ã§ã³ã使ã£ã¦æ¥½ã§ããã¿ããã§ãã
ç¥çµåã«åºæ¥ãã®ã§ãã¹ãã¯å®¹æã«ãªãã®ã§ãããããæ£ç´ãªã¨ãã使ãã¡ãªãããããã®ãã¯è¬ã§ãã
IActionResult
Web API 2.2 㧠IHttpActionResult ã¤ã³ã¿ã¼ãã§ã¼ã¹ã追å ãããã®ã¨åæ§ã«ãMVC 6 ã§ã¯ ActionResult 㨠IHttpActionResult ãçµ±åãããããªæ°ãã IActionResult ã¤ã³ã¿ã¼ãã§ã¼ã¹ã追å ããã¾ããã
public interface IActionResult { Task ExecuteResultAsync(ActionContext context); }https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Core/IActionResult.cs
å½ç¶ãªãã Task ãã¼ã¹ã®éåæã§ããMVC 5 ã¨åããããããã©ã«ãã®å®è£ ãããã®ã§å®å¿åºæ¥ã¾ãã
https://github.com/aspnet/Mvc/tree/dev/src/Microsoft.AspNet.Mvc.Core/ActionResults
ããã¾ã§ã¯ ChallengeResult ã¯ç¡ãã£ãã§ãããèªè¨¼ç³»ãã¡ãã£ã¨ä½ããããããããã¾ããã
View Components
MVC 6 ã§æ°ãã追å ãããã®ããã® View Components ã§ãã大éæã«èª¬æããã¨ã³ã¼ãããã¤ã³ãã®ããé¨åãã¥ã¼ã¨ããæãã§ãããã
View Components — ASP.NET MVC documentation
ããã¾ã§é¨åãã¥ã¼ãçæããããã« DB ããããã¯ã¼ã¯ãããã¼ã¿ãåå¾ããå¿ è¦ãããå ´åã«ã¯ãHtml.Action ã¨ã Html.RenderAction ã使ã£ã¦ããã¨æãã¾ãããMVC 6 ã§ã¯ View Components ã§ç½®ãæããå¯è½ã§ãã
DI ã使ã£ã¦ DbContext ãåãåããã®ã§ãç°¡åã« DB ã使ã£ãã³ã³ãã¼ãã³ããä½ãã¾ãã
View Components — ASP.NET MVC documentation
- Dynamic navigation menus
- Tag cloud (where it queries the database)
- Login panel
- Shopping cart
- Recently published articles
- Any other sidebar content on a typical blog
ä¸å¿ãå ¬å¼ã®ããã¥ã¡ã³ãã§ã¯ä¸ã®æ©è½ãä½ãã¨ãã«ä¾¿å©ã ãï¼ã¨æ¸ãã¦ããã¾ãã
Area
ç¹ã«å¤åã¯ãªãã®ã§ãããArea å±æ§ã使ã£ã¦ã³ã³ããã¼ã©ã¼ãã¨ã«ã¨ãªã¢åãæå®ããããã«ãªãã¾ããã
AreaRegistration ã¯ã©ã¹ã§ã«ã¼ãã£ã³ã°ã¨ã¨ãªã¢åãå®ç¾©ããå¿ è¦ãç¡ããªã£ãã®ã§ãã¡ãã£ã¨æ¥½ã«ãªãã¾ãããåå空éã®ãããã£ã³ã°ã¨ãããã©ãããã£ãã§ããããã®ããããã解æ¾ãããæãããã¾ãã
Routing
ã«ã¼ãã£ã³ã°ã¯ã¡ãã£ã¨ URL ãã³ãã¬ã¼ãã®æ¸ãæ¹ãå¤ããã¾ãããå ·ä½çã«ã¯ Attribute Routing ã¨ã®æè¡·æ¡ã¨ããæãã§ãã
app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action}/{id?}", defaults: new { controller = "Home", action = "Index" }); // Uncomment the following line to add a route for porting Web API 2 controllers. // routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}"); });
Attribute Routing ã使ããã®ã¯ä»ã¾ã§éãã§ãããHttpGet ãªã©ã®å±æ§ã§ãæå®ã§ããããã«ãªã£ã¦ãã¦ãæ£ç´æ··ä¹±æ°å³ã§ãã
Tag Helpers
URL ããªã³ã¯ã®çæã«ã¯ Html.ActionLink ã Url.Action ã使ã£ã¦ãã¾ããããæ°ããå±æ§ã使ã£ã URL çæã®ä»çµã¿ã追å ããã¾ãããæ£ç´ãªã¨ããããã«ä»æ§ãå¤ãããããªã®ã§ããã㯠Scott Hanselman ã®ããã°ãç´¹ä»ãã¦ããã¾ãã
ASP.NET 5 (vNext) Work in Progress - Exploring TagHelpers - Scott Hanselman
ãã®ããããã¡ãã£ã¨å±æ§ããã¾ãã¡ãªæ°ãããªããã¨ããªãã§ãã
Bower / npm / Grunt
ããã¾ã§ã¯ NuGet 㧠JavaScript ç³»ã®ã©ã¤ãã©ãªãå ¥ãã¦ãã¾ããããMVC 6 ãã㯠Bower ã使ã£ã¦å ¥ããããã«ãã¦ããæ¹éã®ããã§ãã
Client-Side Development — ASP.NET documentation
npm 㧠Grunt ãããã©ã«ãã§å ¥ã£ã¦ããã®ã§ãTask Runner Explorer ãã Grunt ã®ãã«ãã¿ã¹ã¯ãèµ°ãããããã¡ãã£ã¨æè¿ã£ã½ãéçºã MVC 6 ã§ãè¡ããããã«ãªãã¾ããã
ã¾ã¨ã
ç¶ã㯠RTM ã«ãªã£ããæ¸ãã¾ãâ¦ã