CR feedback

This commit is contained in:
Ryan Nowak 2014-04-08 12:43:20 -07:00
parent ab605ef935
commit e740633c06
2 changed files with 20 additions and 11 deletions

View File

@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNet.DependencyInjection;
@ -15,6 +17,8 @@ namespace Microsoft.AspNet.Mvc.Razor
private readonly HashSet<string> _renderedSections = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
private bool _renderedBody;
public IViewComponentHelper Component { get; private set; }
public ViewContext Context { get; set; }
public string Layout { get; set; }
@ -42,7 +46,7 @@ namespace Microsoft.AspNet.Mvc.Razor
SectionWriters = new Dictionary<string, HelperResult>(StringComparer.OrdinalIgnoreCase);
Context = context;
Url = context.ServiceProvider.GetService<IUrlHelper>();
InitHelpers();
var contentBuilder = new StringBuilder(1024);
using (var bodyWriter = new StringWriter(contentBuilder))
@ -78,6 +82,21 @@ namespace Microsoft.AspNet.Mvc.Razor
}
}
private void InitHelpers()
{
Contract.Assert(Context != null);
Url = Context.ServiceProvider.GetService<IUrlHelper>();
Component = Context.ServiceProvider.GetService<IViewComponentHelper>();
var contextable = Component as ICanHasViewContext;
if (contextable != null)
{
contextable.Contextualize(Context);
}
}
private async Task RenderLayoutAsync(ViewContext context, string bodyContent)
{
var virtualPathFactory = context.ServiceProvider.GetService<IVirtualPathViewFactory>();

View File

@ -18,8 +18,6 @@ namespace Microsoft.AspNet.Mvc.Razor
public ViewDataDictionary<TModel> ViewData { get; private set; }
public IViewComponentHelper Component { get; private set; }
public IHtmlHelper<TModel> Html { get; set; }
public override Task RenderAsync([NotNull] ViewContext context)
@ -55,14 +53,6 @@ namespace Microsoft.AspNet.Mvc.Razor
{
contextable.Contextualize(context);
}
Component = context.ServiceProvider.GetService<IViewComponentHelper>();
contextable = Component as ICanHasViewContext;
if (contextable != null)
{
contextable.Contextualize(context);
}
}
}
}