public RazorReferenceManager(
     ApplicationPartManager partManager,
     IOptions <MvcRazorRuntimeCompilationOptions> options)
 {
     _partManager = partManager;
     _options     = options.Value;
 }
Example #2
0
        public RuntimeCompilationFileProvider(IOptions <MvcRazorRuntimeCompilationOptions> options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _options = options.Value;
        }
Example #3
0
        private static IFileProvider GetCompositeFileProvider(MvcRazorRuntimeCompilationOptions options)
        {
            var fileProviders = options.FileProviders;

            if (fileProviders.Count == 0)
            {
                var message = $"'{typeof(MvcRazorRuntimeCompilationOptions).FullName}.{nameof(MvcRazorRuntimeCompilationOptions.FileProviders)}' must not be empty. At least one '{typeof(IFileProvider).FullName}' is required to locate a view for rendering.";
                throw new InvalidOperationException(message);
            }
            else if (fileProviders.Count == 1)
            {
                return(fileProviders[0]);
            }

            return(new CompositeFileProvider(fileProviders));
        }
Example #4
0
        private static IFileProvider GetCompositeFileProvider(MvcRazorRuntimeCompilationOptions options)
        {
            var fileProviders = options.FileProviders;

            if (fileProviders.Count == 0)
            {
                var message = Resources.FormatFileProvidersAreRequired(
                    typeof(MvcRazorRuntimeCompilationOptions).FullName,
                    nameof(MvcRazorRuntimeCompilationOptions.FileProviders),
                    typeof(IFileProvider).FullName);
                throw new InvalidOperationException(message);
            }
            else if (fileProviders.Count == 1)
            {
                return(fileProviders[0]);
            }

            return(new CompositeFileProvider(fileProviders));
        }
        public void GetCompilationReferences_CombinesApplicationPartAndOptionMetadataReferences()
        {
            // Arrange
            var options = new MvcRazorRuntimeCompilationOptions();
            var additionalReferencePath = "additional-path";

            options.AdditionalReferencePaths.Add(additionalReferencePath);

            var applicationPartManager = GetApplicationPartManager();
            var referenceManager       = new RazorReferenceManager(
                applicationPartManager,
                Options.Create(options));

            var expected = new[] { ApplicationPartReferencePath, additionalReferencePath };

            // Act
            var references = referenceManager.GetReferencePaths();

            // Assert
            Assert.Equal(expected, references);
        }