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( public RazorPreCompiler(
[NotNull] BeforeCompileContext compileContext, [NotNull] BeforeCompileContext compileContext,
[NotNull] IAssemblyLoadContextAccessor loadContextAccessor, [NotNull] IAssemblyLoadContext loadContext,
[NotNull] IFileProvider fileProvider, [NotNull] IFileProvider fileProvider,
[NotNull] IMemoryCache precompilationCache, [NotNull] IMemoryCache precompilationCache)
[NotNull] CompilationSettings compilationSettings)
{ {
CompileContext = compileContext; CompileContext = compileContext;
LoadContext = loadContextAccessor.GetLoadContext(GetType().GetTypeInfo().Assembly); LoadContext = loadContext;
FileProvider = fileProvider; 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; PreCompilationCache = precompilationCache;
TagHelperTypeResolver = new PrecompilationTagHelperTypeResolver(CompileContext, LoadContext); TagHelperTypeResolver = new PrecompilationTagHelperTypeResolver(CompileContext, LoadContext);
} }

View File

@ -4,7 +4,6 @@
using System; using System;
using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.FileProviders;
using Microsoft.AspNet.Mvc.Razor.Precompilation; using Microsoft.AspNet.Mvc.Razor.Precompilation;
using Microsoft.Dnx.Compilation;
using Microsoft.Dnx.Compilation.CSharp; using Microsoft.Dnx.Compilation.CSharp;
using Microsoft.Dnx.Runtime; using Microsoft.Dnx.Runtime;
using Microsoft.Framework.Caching.Memory; using Microsoft.Framework.Caching.Memory;
@ -17,7 +16,7 @@ namespace Microsoft.AspNet.Mvc
/// </summary> /// </summary>
public abstract class RazorPreCompileModule : ICompileModule public abstract class RazorPreCompileModule : ICompileModule
{ {
private readonly IServiceProvider _appServices; private readonly IAssemblyLoadContext _loadContext;
private readonly IMemoryCache _memoryCache; private readonly IMemoryCache _memoryCache;
/// <summary> /// <summary>
@ -26,7 +25,7 @@ namespace Microsoft.AspNet.Mvc
/// <param name="services">The <see cref="IServiceProvider"/> for the application.</param> /// <param name="services">The <see cref="IServiceProvider"/> for the application.</param>
public RazorPreCompileModule(IServiceProvider services) public RazorPreCompileModule(IServiceProvider services)
{ {
_appServices = services; _loadContext = services.GetRequiredService<IAssemblyLoadContext>();
// When CompactOnMemoryPressure is true, the MemoryCache evicts items at every gen2 collection. // 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 // 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> /// <remarks>Pre-compiles all Razor views in the application.</remarks>
public virtual void BeforeCompile(BeforeCompileContext context) 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 fileProvider = new PhysicalFileProvider(context.ProjectContext.ProjectDirectory);
var viewCompiler = new RazorPreCompiler( var viewCompiler = new RazorPreCompiler(
context, context,
loadContextAccessor, _loadContext,
fileProvider, fileProvider,
_memoryCache, _memoryCache)
compilationSettings)
{ {
GenerateSymbols = GenerateSymbols GenerateSymbols = GenerateSymbols
}; };
@ -65,15 +60,5 @@ namespace Microsoft.AspNet.Mvc
public void AfterCompile(AfterCompileContext context) 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);
}
} }
} }