ç°¡åã«ããããã«ãç¹å¥ãªãã¹ããœãªã¥ãŒã·ã§ã³AspNet5ModularAppãæºåããGitHubã«æçš¿ããŸãã ã åºæ¬çã«ããã®èšäºã§ã¯åœŒã«é ŒããŸãããPlatformusã§äœ¿çšããããªãã¯ãã¢ã€ãã¢ã®äžéšã«ã觊ããŸãïŒéšåçã«ã¯ãã³ã¡ã³ããåãåãããšãæåŸ ããŠïŒã

äž»ãªã¿ã¹ã¯ã®æ±ºå®
CMSã®éçºã«åºæã®åé¡ãçç¥ããå Žåãç§ã«ãšã£ãŠã®äž»ãªã¿ã¹ã¯ã¯ãããžã§ã¯ãã®æèœãªã¢ãžã¥ãŒã«ã¢ãŒããã¯ãã£ã§ããïŒãããŠããŸã æ®ã£ãŠããŸãïŒã
ã¡ã€ã³ã®Webã¢ããªã±ãŒã·ã§ã³ã«ã¯ã³ã³ãããŒã©ãŒããã¥ãŒããŸãã¯ãªãœãŒã¹ïŒã¹ã¯ãªãããã¹ã¿ã€ã«ãç»åãªã©ïŒãå«ããã¹ãã§ã¯ãªããããŒã¿ããããã®ä¿åæ¹æ³ã«ã€ããŠã¯ç¥ããªãããæ¡åŒµæ©èœïŒã¢ã»ã³ããªãŒã®ã»ããïŒã«ã€ããŠã¯ç¥ã£ãŠããã¹ãã ãšå€æããŸããïŒ ãã®å Žåã圌ã®å¯äžã®ã¿ã¹ã¯ã¯ããã¹ãŠã®æ¡åŒµæ©èœãèŠã€ããŠããŠã³ããŒãããåæåããããšã§ãã
åæ§ã«ãæ¡åŒµæ©èœã¯å ±éã®ã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ããå¿ èŠããããå®éã«ã¯äœã§ãå«ããããšãã§ããŸãã ïŒãã ããç§ã®å Žåãã»ãŒãã¹ãŠã®æ¡åŒµæ©èœãããŒã¿ãåŠçããããããã®ã¡ã«ããºã ã説æããæœè±¡åã¬ãã«ãè¿œå ããŸãããããã«ããããã¹ãŠã®æ¡åŒµæ©èœãçµ±äžãããã³ã³ããã¹ãã§ããŒã¿ãåŠçã§ããŸããããã¯ååã«éèŠã§ããããã¯ä»¥äžã§ããïŒ
ã»ãšãã©ã®å Žåãæ¡åŒµæ©èœã«ã¯ã³ã³ãããŒã©ãŒãšãã¥ãŒãå«ãŸããŠããå¿ èŠããããããæåã«ã³ã³ãããŒã©ãŒãšãã¥ãŒãåäœãããããšããã®ã¯ãåçã«èªã¿èŸŒãŸããã¢ã»ã³ããªïŒã€ãŸããã¡ã€ã³Webã¢ããªã±ãŒã·ã§ã³ã®project.jsonã§æ瀺çã«åç §ãããŠããªãã¢ã»ã³ããªèµ·ååŸã«æ¡åŒµæ©èœã䜿çšããŠãã£ã¬ã¯ããªããããŒããããŸãïŒã
ã³ã³ãããŒã©ãŒã«åé¡ã¯ãããŸããã§ããã IAssemblyProviderã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ããDefaultAssemblyProviderããã¢ã»ã³ããªãã³ããŒããŠãæ¡åŒµãã£ã¬ã¯ããªããåçã«ããŒããããã¢ã»ã³ããªãè¿œå ãïŒ AspNet5ModularApp.ExtensionAssemblyProviderãåç §ïŒãæ°ããå®è£ ãConfigureServicesã«ç»é²ããŸãïŒ AspNet5ModularApp.Startupãåç §ïŒã å¯äžã®ãã®ïŒããã©ã«ãã§ã¯ãMVCã¯Microsoft.AspNet.Mvcã®ãããªãã®ãåç §ããã¢ã»ã³ããªå ã®ã³ã³ãããŒã©ãŒãæ¢ããŸãã ç§ã®å Žåãã»ãšãã©ãã¹ãŠã®ãããžã§ã¯ãããã®ã¢ã»ã³ããªãåç §ããŠããããïŒããã¯æªãããšã§ããããªããããŸã§ã®ãšãããããªã£ãã®ãã以äžã§èª¬æããŸãïŒããã¹ãŠã®ãããžã§ã¯ãã§æ€çŽ¢ãè¡ããã確ãã«ããã©ãŒãã³ã¹ã«æªåœ±é¿ãåãŒããŸãããã®å Žåããããä¿®æ£ããå¿ èŠããããŸãïŒãã¡ããããã¹ããœãªã¥ãŒã·ã§ã³ã§ã¯ããã©ãŒãã³ã¹ã®åé¡ã¯ãããŸããïŒã
ç§ã¯å°ãèããããããªããã°ãªããŸããã§ããã ç§ãç¥ãéããviewsãªãœãŒã¹ãäœæããïŒããšãã°ãproject.jsonã«æåå "resource"ïŒ "Views / **"ãè¿œå ããïŒãããã¥ãŒã®äºåã³ã³ãã€ã«ã䜿çšããïŒRazorPreCompileModuleããç¶æ¿ããRazorPreCompilationã¯ã©ã¹ãè¿œå ããïŒããšãã§ããŸãã ãã®å Žåãæåã«ããã€ãã£ãã¿ã€ãã§åä»ããããè¡šçŸã䜿çšã§ããããã2çªç®ã®ãªãã·ã§ã³ã奜ã¿ãŸãïŒã€ãŸãããã¥ãŒèªäœãå«ãã¢ã»ã³ããªå ã§å®çŸ©ãããã¿ã€ããæå³ããŸã-ãªãœãŒã¹ãã¥ãŒã®å Žåããã®ãããªã¿ã€ãã¯GitHub ASP.NETã«é¢ããç§ã®è³ªåãžã®åçããç解ããéãããã®åé¡ã解決ã§ããŸãïŒããããŠã第äºã«ã圌ãã¯åã«ã©ã³ã¿ã€ã ã§ã³ã³ãã€ã«ãå¿ èŠãšããªããããæåã®ã¢ã¯ã»ã¹ã§ããéãããŒããããŸãã ããŠããã¥ãŒã®ãã¹ãŠã®ãšã©ãŒã¯ãã³ã³ãã€ã«ã®æ®µéã§ãã§ã«æããã«ãªã£ãŠããŸãã
ãã¹ããœãªã¥ãŒã·ã§ã³AspNet5ModularAppã®ã¡ã€ã³Webã¢ããªã±ãŒã·ã§ã³ã¯ããããã®ãªãã·ã§ã³ã®äž¡æ¹ãåæã«ãµããŒãããŸãã察å¿ããåäœã¯ãAddPrecompiledRazorViewsããã³AddRazorOptionsé¢æ°ã䜿çšããŠèšå®ãããŸãïŒ Startup.csãåç §ïŒã
ããªã³ã³ãã€ã«ããããã¥ãŒã®æäœã®ããã«ãããããå«ãã¢ã»ã³ããªãã€ã³ã¹ããŒã«ããã ãã§ååãªå Žåã¯ããªãœãŒã¹ãã¥ãŒã§IFileProviderã€ã³ã¿ãŒãã§ã€ã¹ãå®è£ ãïŒ AspNet5ModularApp.CompositeFileProviderãåç §ïŒããã¡ã€ã«ã®ãœãŒã¹ãšããŠã¡ã€ã³Webã¢ããªã±ãŒã·ã§ã³ãæå®ããå¿ èŠããããŸãïŒããã©ã«ãã§ã¯ãããåœãŠã¯ãŸããŸãïŒãã¥ãŒãå«ãåçã«ããŒãããããã¹ãŠã®ã¢ã»ã³ããªã ãšããã§ããªãœãŒã¹ã¯è¡šçŸã ãã§ãªããã¹ã¯ãªãããã¹ã¿ã€ã«ãç»åãªã©ã«ããªããŸãã ããããå«ãã¢ã»ã³ããªãCompositeFileProviderã«è¿œå ãããåŸããããã¯ã¢ã»ã³ããªå ã«é 眮ãããŠãããã¹ã«æ²¿ã£ãŠäœ¿çšå¯èœã«ãªããŸãã
ExtensionAã¯æåã®ãªãã·ã§ã³ïŒãªãœãŒã¹ãã¥ãŒïŒã瀺ããExtensionBã¯2çªç®ïŒããªã³ã³ãã€ã«æžã¿ãã¥ãŒïŒã瀺ããŸãã
ããã§ã解決çããŸã èŠã€ãã£ãŠããªãããã€ãã®åé¡ã«ã€ããŠè©±ãå¿ èŠããããŸãã
ãŸããASP.NET 5ã®ç°ãªãéšåã¯ç°ãªãããŒãžã§ã³ã®ã·ã¹ãã ã䜿çšããŸã*ã¢ã»ã³ããªãããšãã°ããããããžã§ã¯ãã§Microsoft.AspNet.Mvcãæ¥ç¶ããå¥ã®ãããžã§ã¯ãã§System.Runtimeãæ¥ç¶ããããšãããšã䜿çšãããŠãããšãããšã©ãŒãçºçããŸããåãã©ã€ãã©ãªã®ç°ãªãããŒãžã§ã³ã çŸæç¹ã§ã¯ãAspNet5ModularAppã¯ASP.NET 5ã®8çªç®ã®ããŒã¿çã«åºã¥ããŠæ§ç¯ãããŠããããããã®ãªãªãŒã¹ã§ä¿®æ£ããããšæããŸãã ãããŸã§ã¯ãMicrosoft.AspNet.Mvcããã¹ãŠã®ãããžã§ã¯ãã«ç»é²ããŸããïŒEntity Frameworkã§åäœãããããžã§ã¯ããé€ã-Entity Frameworkèªäœã§ååã§ãïŒãåãäŸåé¢ä¿ã®ã»ãããååŸããŸãã ç§ã¯åæããŸãããããã¯éåžžã«æªãããšã§ãããäºçŽ°ãªããšã«æéãç¡é§ã«ããªãããã«ããŸããã
2çªç®ã®ïŒããããããæ·±å»ãªïŒåé¡ã¯ãæ¡åŒµæ©èœã¢ã»ã³ããªãæ¡åŒµæ©èœã䜿çšããŠãã£ã¬ã¯ããªã«ã³ããŒããã¡ã€ã³ã®Webã¢ããªã±ãŒã·ã§ã³ã䜿çšããªããã®ãã¢ã»ã³ããªã䜿çšããå Žåã察å¿ããäŸåé¢ä¿ãããã«ã³ããŒããå¿ èŠãããããšã§ãã ããšãã°ãSystem.Reflection.dllããã³System.Reflection.TypeExtensions.dllã®æ¡åŒµåãæã€ãã£ã¬ã¯ããªã«é 眮ããå¿ èŠããããŸããïŒããã§ãªãå Žåãäžèšã®äŸåé¢ä¿ãæã€ã¢ã»ã³ããªãããŒãããããšãããšäŸå€ãçºçããŸãïŒã ããããææªã®éšåã¯ãEntityFramework.Sqliteã§ç²åŸã§ããã¢ã»ã³ããªã®ã»ãããéžæã§ããªãã£ãããšã§ãã ãããã£ãŠãã¡ã€ã³ã¢ããªã±ãŒã·ã§ã³ã®project.jsonã«EntityFramework.Sqliteãžã®æ瀺çãªãªã³ã¯ãå«ããå¿ èŠããããŸããïŒãããŠãç¹å®ã®å®è£ ã¯èšããŸã§ããªããããŒã¿ã«ã€ããŠãŸã£ããç¥ããããªãããšãäžèšã§æžããŸããïŒã ïŒã¡ãªã¿ã«ãGACã®.dnxã«ããã¢ã»ã³ããªãç»é²ããã°ãã¹ãŠåé¡ãããŸããããããã¯ééã£ãŠããããã§ããïŒ
次ã«ãããŒã¿ãšãã®ã¹ãã¬ãŒãžãæ±ãå§ããŸããã æ¡åŒµæ©èœãããŸããŸãªããŒã¿ãœãŒã¹ã§åäœããç¹å®ã®å®è£ ã決å®ããã«ã¯ãå¿ èŠãªã¢ã»ã³ããªãæ¡åŒµæ©èœã®ãããã£ã¬ã¯ããªã«ã³ããŒããã ãã§ååã§ããã
AspNet5ModularApp.Models.Abstractionsãããžã§ã¯ãã§ã¯ãã¢ãã«ã®åºæ¬ã€ã³ã¿ãŒãã§ã€ã¹ã§ããIEntityãå®çŸ©ããŸããã AspNet5ModularApp.Data.Abstractionsãããžã§ã¯ãã§ã¯ã IStorageContextãIStorageãIRepositoryã®3ã€ã®åºæ¬çãªã€ã³ã¿ãŒãã§ã€ã¹ãå®çŸ©ããŸããã Entity Framework 7ã䜿çšããŠSqliteããŒã¿ããŒã¹ãæäœããããã®ãããã®ã€ã³ã¿ãŒãã§ã€ã¹ã®å®è£ ãå«ãAspNet5ModularApp.Data.EF.Sqliteãããžã§ã¯ãã¯ããã®ç®çãæããã瀺ããŠããŸãããŸãããã®ãããžã§ã¯ãã¯ãæ¡åŒµæ©èœãã¢ãã«ãåäžã®ã³ã³ããã¹ãã«ç»é²ã§ããIModelRegistrarã€ã³ã¿ãŒãã§ã€ã¹ãå®çŸ©ããŸãïŒåç §AspNet5ModularApp.Data.EF.Sqlite.StorageContext.OnModelCreating ïŒã
äžè¬çãªåäœåçã¯æ¬¡ã®ãšããã§ãã æ¡åŒµæ©èœã¯ãè€æ°ã®ãããžã§ã¯ãã§æ§æã§ããŸãïŒã³ã³ãããŒã©ãŒãšãã¥ãŒãå«ããããžã§ã¯ããã¢ãã«ãå«ããããžã§ã¯ããããŒã¿ãœãŒã¹ãæäœããããã®ãªããžããªã®æœè±¡åãå«ããããžã§ã¯ãïŒåã¢ãã«ã«1ã€ïŒãããã³ãããã®æœè±¡åãå®è£ ãããããžã§ã¯ãïŒåããŒã¿ãœãŒã¹ã«1ã€ã®ãããžã§ã¯ãïŒã ã³ã³ãããŒã©ãšãã¥ãŒãæã€ãããžã§ã¯ãã¯ããªããžããªã®ã¢ãã«ãšæœè±¡åã«ã€ããŠã¯ç¥ã£ãŠããŸãããç¹å®ã®ããŒã¿ãœãŒã¹ã®å®è£ ã«ã€ããŠã¯ç¥ããŸããã ãããã£ãŠãã³ã³ãããŒã©ãŒã®ã³ã³ã¹ãã©ã¯ã¿ãŒã§ãASP.NET 5 DIãã«ãã€ã³ã«IStorageã®ã¢ã¯ã»ã¹å¯èœãªã€ã³ã¹ã¿ã³ã¹ãæäŸããããã«èŠæ±ããããã«ãã€ã³ã¿ãŒãã§ã€ã¹ããç¹å®ã®ãªããžããªã®å©çšå¯èœãªå®è£ ãèŠæ±ããããšãã§ããŸãã ïŒãã¡ãããçµã¿èŸŒã¿ã®DIãIStorageã®ã¢ã¯ã»ã¹å¯èœãªå®è£ ãèŠã€ããããã«ã AspNet5ModularApp.ExtensionB.ExtensionB.ConfigureServicesã§è¡ãããŠããããšãéç¥ããå¿ èŠããããŸãããããåæ¡åŒµæ©èœã§è¡ããªãããã«ãPlatformusã§ã¯äžè¬çãªæ©èœããã¢ããŒã³ã«åããŸãã ïŒ
çµæ
çµæãšããŠäœãèµ·ãã£ãã®ãã ç§ãæžããäŸåçã®åé¡ã«ç®ãã€ã¶ããšãããã«è§£æ±ºãããå¯èœæ§ãé«ãã®ã§ãç§ã®æèŠã§ã¯ããã¹ãŠã®è³ªåã«å¯ŸããçããèŠã€ããŸããã æ¡åŒµæ©èœã䜿çšããŠãã£ã¬ã¯ããªã«ã¢ã»ã³ããªãã³ããŒããã ãã§ãã¢ããªã±ãŒã·ã§ã³ã®æ©èœãæ¡åŒµã§ããŸããæ¡åŒµæ©èœã«ã¯ã匷ãåä»ãããããã¥ãŒãšãããŒã¿ãœãŒã¹ãæäœããããã®åäžã®ã³ã³ããã¹ããå«ããããšãã§ããŸãã å¿ èŠã«å¿ããŠãã¢ããªã±ãŒã·ã§ã³ã®ããã»ã¹ã§çŽæ¥æ¡åŒµæ©èœãè¿œå ããã³åé€ã§ããããã«ããããšã¯é£ãããããŸããã åæ€çŽ¢ãšã³ãžã³ã«ãã£ãã·ã³ã°ãè¿œå ããããšã«ãããããã©ãŒãã³ã¹ãå€§å¹ ã«æ¹åããããšãã§ããŸãã
ç§ã¯ã³ã¡ã³ããšçºèšãåãã§ããã ããããèšäºã§ããŸãè¿°ã¹ãããªãã£ããããã®ãã€ã³ããæ確ã«ããããšãåãã§ããã ããã
ãªã³ã¯ãšæè¬
AspNet5ModularAppãžã®ãªã³ã¯ ã
GitHubãŠãŒã¶ãŒgithub.com/leo9223ã«æè¬ããŸãã ãã®ãããžã§ã¯ããèŠããŠãããŠãç§ã倧ãã«å©ããŠãããŸããã ãã®ãããžã§ã¯ãã¯ããªãœãŒã¹ãã¥ãŒãç解ããã®ã«åœ¹ç«ã¡ãŸããããããã§ãæ©èœãããããšã¯ã§ããŸããã§ããã ä»ãç§ã¯ãã§ã«ãã®çç±ãç¥ã£ãŠããŸãã æ¡åŒµæ©èœãæã€ã¢ã»ã³ããªããEmbeddedFileProviderãäœæãããšãã«ãããŒã¹åå空éãããã«æå®ãããŠããªãã£ãããããã¥ãŒãèŠã€ãããŸããã§ããã ããã§æããããèŠã€ããŸããã ãŸããGitHub for ASP.NETéçºè ã«é¢ããç§ã®è³ªåãžã®åçã¯ã圌ãã®å¿èãšæ³šæã«æè¬ããŸããã