React to dnx refactoring changes

- Use compilation options from the Compilation itself
- Get the parse options from the first syntax tree
- Get the build time IAssemblyLoadContext directly
This commit is contained in:
David Fowler 2015-08-19 03:04:10 -07:00
parent a0879cc37f
commit 485e6e5ee8
2 changed files with 14 additions and 24 deletions

View File

@ -26,15 +26,20 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation
{
public RazorPreCompiler(
[NotNull] BeforeCompileContext compileContext,
[NotNull] IAssemblyLoadContextAccessor loadContextAccessor,
[NotNull] IAssemblyLoadContext loadContext,
[NotNull] IFileProvider fileProvider,
[NotNull] IMemoryCache precompilationCache,
[NotNull] CompilationSettings compilationSettings)
[NotNull] IMemoryCache precompilationCache)
{
CompileContext = compileContext;
LoadContext = loadContextAccessor.GetLoadContext(GetType().GetTypeInfo().Assembly);
LoadContext = loadContext;
FileProvider = fileProvider;
CompilationSettings = compilationSettings;
CompilationSettings = new CompilationSettings
{
CompilationOptions = compileContext.Compilation.Options,
// REVIEW: There should always be a syntax tree even if there are no files (we generate one)
Defines = compileContext.Compilation.SyntaxTrees[0].Options.PreprocessorSymbolNames,
LanguageVersion = compileContext.Compilation.LanguageVersion
};
PreCompilationCache = precompilationCache;
TagHelperTypeResolver = new PrecompilationTagHelperTypeResolver(CompileContext, LoadContext);
}

View File

@ -4,7 +4,6 @@
using System;
using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Mvc.Razor.Precompilation;
using Microsoft.Dnx.Compilation;
using Microsoft.Dnx.Compilation.CSharp;
using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Caching.Memory;
@ -17,7 +16,7 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
public abstract class RazorPreCompileModule : ICompileModule
{
private readonly IServiceProvider _appServices;
private readonly IAssemblyLoadContext _loadContext;
private readonly IMemoryCache _memoryCache;
/// <summary>
@ -26,7 +25,7 @@ namespace Microsoft.AspNet.Mvc
/// <param name="services">The <see cref="IServiceProvider"/> for the application.</param>
public RazorPreCompileModule(IServiceProvider services)
{
_appServices = services;
_loadContext = services.GetRequiredService<IAssemblyLoadContext>();
// When CompactOnMemoryPressure is true, the MemoryCache evicts items at every gen2 collection.
// In DTH, gen2 happens frequently enough to make it undesirable for caching precompilation results. We'll
@ -43,17 +42,13 @@ namespace Microsoft.AspNet.Mvc
/// <remarks>Pre-compiles all Razor views in the application.</remarks>
public virtual void BeforeCompile(BeforeCompileContext context)
{
var compilerOptionsProvider = _appServices.GetRequiredService<ICompilerOptionsProvider>();
var loadContextAccessor = _appServices.GetRequiredService<IAssemblyLoadContextAccessor>();
var compilationSettings = GetCompilationSettings(compilerOptionsProvider, context.ProjectContext);
var fileProvider = new PhysicalFileProvider(context.ProjectContext.ProjectDirectory);
var viewCompiler = new RazorPreCompiler(
context,
loadContextAccessor,
_loadContext,
fileProvider,
_memoryCache,
compilationSettings)
_memoryCache)
{
GenerateSymbols = GenerateSymbols
};
@ -65,15 +60,5 @@ namespace Microsoft.AspNet.Mvc
public void AfterCompile(AfterCompileContext context)
{
}
private static CompilationSettings GetCompilationSettings(
ICompilerOptionsProvider compilerOptionsProvider,
ProjectContext projectContext)
{
return compilerOptionsProvider.GetCompilerOptions(projectContext.Name,
projectContext.TargetFramework,
projectContext.Configuration)
.ToCompilationSettings(projectContext.TargetFramework);
}
}
}