diff --git a/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs b/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs index fc8c70c364..2f01519b1f 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ActionResults/ViewResult.cs @@ -19,14 +19,14 @@ namespace Microsoft.AspNet.Mvc _viewEngine = viewEngine; } - public string ViewName {get; set; } + public string ViewName { get; set; } public ViewDataDictionary ViewData { get; set; } public async Task ExecuteResultAsync([NotNull] ActionContext context) { var viewName = ViewName ?? context.ActionDescriptor.Name; - var view = await FindView(context.RouteValues, viewName); + var view = FindView(context.RouteValues, viewName); using (view as IDisposable) { @@ -39,10 +39,9 @@ namespace Microsoft.AspNet.Mvc } } - private async Task FindView([NotNull] IDictionary context,[NotNull] string viewName) + private IView FindView([NotNull] IDictionary context, [NotNull] string viewName) { - var result = await _viewEngine.FindView(context, viewName); - + var result = _viewEngine.FindView(context, viewName); return result.View; } diff --git a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewViewComponentResult.cs b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewViewComponentResult.cs index ac60243972..0d4cfe0d6b 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewViewComponentResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ViewComponents/ViewViewComponentResult.cs @@ -68,17 +68,16 @@ namespace Microsoft.AspNet.Mvc _viewName); } - var view = await FindView(context.ViewContext.ViewEngineContext, qualifiedViewName); + var view = FindView(context.ViewContext.ViewEngineContext, qualifiedViewName); using (view as IDisposable) { await view.RenderAsync(childViewContext); } } - private async Task FindView([NotNull] IDictionary context, [NotNull] string viewName) + private IView FindView([NotNull] IDictionary context, [NotNull] string viewName) { - var result = await _viewEngine.FindView(context, viewName); - + var result = _viewEngine.FindView(context, viewName); return result.View; } } diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs index b579772774..cebbc00c35 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Concurrent; -using System.Threading.Tasks; using Microsoft.AspNet.FileSystems; namespace Microsoft.AspNet.Mvc.Razor @@ -14,7 +13,7 @@ namespace Microsoft.AspNet.Mvc.Razor _cache = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); } - public async Task GetOrAdd(IFileInfo file, Func> compile) + public CompilationResult GetOrAdd(IFileInfo file, Func compile) { // Generate a content id string contentId = file.PhysicalPath + '|' + file.LastModified.Ticks; @@ -22,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.Razor Type compiledType; if (!_cache.TryGetValue(contentId, out compiledType)) { - CompilationResult result = await compile(); + CompilationResult result = compile(); _cache.TryAdd(contentId, result.CompiledType); return result; diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/ICompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/ICompilationService.cs index a1f9064520..128bae7fe4 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/ICompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/ICompilationService.cs @@ -5,6 +5,6 @@ namespace Microsoft.AspNet.Mvc.Razor { public interface ICompilationService { - Task Compile(string content); + CompilationResult Compile(string content); } } diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs index 4c34b968e3..51b86d9fed 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/RoslynCompilationService.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation _libraryManager = libraryManager; } - public Task Compile(string content) + public CompilationResult Compile(string content) { var syntaxTrees = new[] { CSharpSyntaxTree.ParseText(content) }; var targetFramework = _environment.TargetFramework; @@ -51,14 +51,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation var messages = result.Diagnostics.Where(IsError).Select(d => GetCompilationMessage(formatter, d)).ToList(); - return Task.FromResult(CompilationResult.Failed(content, messages)); + return CompilationResult.Failed(content, messages); } var type = _loader.LoadBytes(ms.ToArray(), pdb.ToArray()) .GetExportedTypes() .First(); - return Task.FromResult(CompilationResult.Successful(String.Empty, type)); + return CompilationResult.Successful(String.Empty, type); } } } diff --git a/src/Microsoft.AspNet.Mvc.Razor/Razor/IRazorCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Razor/IRazorCompilationService.cs index b22c9af035..a5aca2532e 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Razor/IRazorCompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Razor/IRazorCompilationService.cs @@ -1,10 +1,9 @@ -using System.Threading.Tasks; -using Microsoft.AspNet.FileSystems; +using Microsoft.AspNet.FileSystems; namespace Microsoft.AspNet.Mvc.Razor { public interface IRazorCompilationService { - Task Compile(IFileInfo fileInfo); + CompilationResult Compile(IFileInfo fileInfo); } } diff --git a/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs b/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs index 9703ec6779..2fde1757e4 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Razor/RazorCompilationService.cs @@ -2,7 +2,6 @@ using System.Diagnostics.Contracts; using System.IO; using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNet.FileSystems; using Microsoft.AspNet.Razor; using Microsoft.Net.Runtime; @@ -27,13 +26,13 @@ namespace Microsoft.AspNet.Mvc.Razor _appRoot = EnsureTrailingSlash(environment.ApplicationBasePath); } - public Task Compile([NotNull]IFileInfo file) + public CompilationResult Compile([NotNull]IFileInfo file) { return _cache.GetOrAdd(file, () => CompileCore(file)); } // TODO: Make this internal - public async Task CompileCore(IFileInfo file) + public CompilationResult CompileCore(IFileInfo file) { GeneratorResults results; using (Stream inputStream = file.CreateReadStream()) @@ -49,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.Razor throw new CompilationFailedException(messages, results.GeneratedCode); } - return await _baseCompilationService.Compile(results.GeneratedCode); + return _baseCompilationService.Compile(results.GeneratedCode); } private static string EnsureTrailingSlash([NotNull]string path) diff --git a/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs b/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs index 73dd11b76d..3a742c98a8 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs @@ -74,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.Razor private async Task RenderLayoutAsync(ViewContext context, string bodyContent) { var virtualPathFactory = context.ServiceProvider.GetService(); - var layoutView = (RazorView)(await virtualPathFactory.CreateInstance(Layout)); + var layoutView = (RazorView)virtualPathFactory.CreateInstance(Layout); if (layoutView == null) { diff --git a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/IVirtualPathViewFactory.cs b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/IVirtualPathViewFactory.cs index 0c6651a6f9..f6f840d05d 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/IVirtualPathViewFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/IVirtualPathViewFactory.cs @@ -1,11 +1,10 @@  -using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Rendering; namespace Microsoft.AspNet.Mvc.Razor { public interface IVirtualPathViewFactory { - Task CreateInstance(string virtualPath); + IView CreateInstance(string virtualPath); } } diff --git a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs index f01d212dad..90a287bca2 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/RazorViewEngine.cs @@ -28,10 +28,10 @@ namespace Microsoft.AspNet.Mvc.Razor get { return _viewLocationFormats; } } - public async Task FindView([NotNull] IDictionary context, - [NotNull] string viewName) + public ViewEngineResult FindView([NotNull] IDictionary context, + [NotNull] string viewName) { - var viewEngineResult = await CreateViewEngineResult(context, viewName); + var viewEngineResult = CreateViewEngineResult(context, viewName); var errorMessage = Resources.FormatViewEngine_ViewNotFound( viewName, ToLocationString(viewEngineResult.SearchedLocations)); @@ -41,10 +41,10 @@ namespace Microsoft.AspNet.Mvc.Razor return viewEngineResult; } - public async Task FindPartialView([NotNull] IDictionary context, - [NotNull] string partialViewName) + public ViewEngineResult FindPartialView([NotNull] IDictionary context, + [NotNull] string partialViewName) { - var viewEngineResult = await CreateViewEngineResult(context, partialViewName); + var viewEngineResult = CreateViewEngineResult(context, partialViewName); var errorMessage = Resources.FormatViewEngine_PartialViewNotFound( partialViewName, ToLocationString(viewEngineResult.SearchedLocations)); @@ -54,14 +54,14 @@ namespace Microsoft.AspNet.Mvc.Razor return viewEngineResult; } - private async Task CreateViewEngineResult([NotNull] IDictionary context, - [NotNull] string viewName) + private ViewEngineResult CreateViewEngineResult([NotNull] IDictionary context, + [NotNull] string viewName) { var nameRepresentsPath = IsSpecificPath(viewName); if (nameRepresentsPath) { - var view = await _virtualPathFactory.CreateInstance(viewName); + var view = _virtualPathFactory.CreateInstance(viewName); return view != null ? ViewEngineResult.Found(viewName, view) : ViewEngineResult.NotFound(viewName, new[] { viewName }); } @@ -74,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.Razor for (int i = 0; i < _viewLocationFormats.Length; i++) { var path = String.Format(CultureInfo.InvariantCulture, _viewLocationFormats[i], viewName, controllerName, areaName); - IView view = await _virtualPathFactory.CreateInstance(path); + IView view = _virtualPathFactory.CreateInstance(path); if (view != null) { return ViewEngineResult.Found(viewName, view); diff --git a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/VirtualPathViewFactory.cs b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/VirtualPathViewFactory.cs index 8caae5ba05..8fbd109ed8 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/VirtualPathViewFactory.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/ViewEngine/VirtualPathViewFactory.cs @@ -19,12 +19,12 @@ namespace Microsoft.AspNet.Mvc.Razor _compilationService = compilationService; } - public async Task CreateInstance([NotNull]string virtualPath) + public IView CreateInstance([NotNull]string virtualPath) { IFileInfo fileInfo; if (_fileSystem.TryGetFileInfo(virtualPath, out fileInfo)) { - CompilationResult result = await _compilationService.Compile(fileInfo); + CompilationResult result = _compilationService.Compile(fileInfo); return (IView)Activator.CreateInstance(result.CompiledType); } diff --git a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs index b1c64b482e..49c89e89a8 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/Html/HtmlHelper.cs @@ -180,7 +180,7 @@ namespace Microsoft.AspNet.Mvc.Rendering Writer = writer }; - var viewEngineResult = await _viewEngine.FindPartialView(newViewContext.ViewEngineContext, partialViewName); + var viewEngineResult = _viewEngine.FindPartialView(newViewContext.ViewEngineContext, partialViewName); await viewEngineResult.View.RenderAsync(newViewContext); } diff --git a/src/Microsoft.AspNet.Mvc.Rendering/View/IViewEngine.cs b/src/Microsoft.AspNet.Mvc.Rendering/View/IViewEngine.cs index b1325af6b4..80c757ef7a 100644 --- a/src/Microsoft.AspNet.Mvc.Rendering/View/IViewEngine.cs +++ b/src/Microsoft.AspNet.Mvc.Rendering/View/IViewEngine.cs @@ -1,11 +1,11 @@ using System.Collections.Generic; -using System.Threading.Tasks; namespace Microsoft.AspNet.Mvc.Rendering { public interface IViewEngine { - Task FindView([NotNull] IDictionary context, [NotNull] string viewName); - Task FindPartialView([NotNull] IDictionary context, [NotNull] string partialViewName); + ViewEngineResult FindView([NotNull] IDictionary context, [NotNull] string viewName); + + ViewEngineResult FindPartialView([NotNull] IDictionary context, [NotNull] string partialViewName); } } diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorCompilationServiceTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorCompilationServiceTest.cs index 259d5a4de5..ab965e42ae 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorCompilationServiceTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorCompilationServiceTest.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.IO; using Microsoft.AspNet.FileSystems; using Microsoft.AspNet.Razor; using Microsoft.AspNet.Razor.Generator.Compiler; @@ -31,7 +26,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test .Verifiable(); var compiler = new Mock(); compiler.Setup(c => c.Compile(It.IsAny())) - .Returns(Task.FromResult(CompilationResult.Successful("", typeof(RazorCompilationServiceTest)))); + .Returns(CompilationResult.Successful("", typeof(RazorCompilationServiceTest))); var razorService = new RazorCompilationService(env.Object, compiler.Object, host.Object); var fileInfo = new Mock(); @@ -39,7 +34,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test fileInfo.Setup(f => f.CreateReadStream()).Returns(Stream.Null); // Act - razorService.CompileCore(fileInfo.Object).Wait(); + razorService.CompileCore(fileInfo.Object); // Assert host.Verify();