// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; using System.Linq; using Microsoft.CodeAnalysis; using Microsoft.Extensions.DependencyModel; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.Extensions.PlatformAbstractions; namespace Microsoft.AspNet.Mvc.Razor.Compilation { /// /// A type that uses Roslyn to compile C# content and to locate references. /// public class DependencyContextCompilationService : RoslynCompilationService { private readonly DependencyContext _dependencyContext; /// /// Initalizes a new instance of the class. /// /// The environment for the executing application. /// The that was used to generate the code. /// Accessor to . /// The . /// The . public DependencyContextCompilationService( IApplicationEnvironment environment, IMvcRazorHost host, IOptions optionsAccessor, IRazorViewEngineFileProviderAccessor fileProviderAccessor, ILoggerFactory loggerFactory) : this(DependencyContext.Default, environment, host, optionsAccessor, fileProviderAccessor, loggerFactory) { } /// /// Initalizes a new instance of the class. /// /// to use for reference resolution. /// The environment for the executing application. /// The that was used to generate the code. /// Accessor to . /// The . /// The . public DependencyContextCompilationService( DependencyContext dependencyContext, IApplicationEnvironment environment, IMvcRazorHost host, IOptions optionsAccessor, IRazorViewEngineFileProviderAccessor fileProviderAccessor, ILoggerFactory loggerFactory) : base(environment, host, optionsAccessor, fileProviderAccessor, loggerFactory) { _dependencyContext = dependencyContext; } protected override List GetApplicationReferences() { return _dependencyContext.CompileLibraries .SelectMany(library => library.ResolveReferencePaths()) .Select(CreateMetadataFileReference) .ToList(); } } }