private CompilationResult GetCompilation(RazorProjectItem projectItem, RazorProjectFileSystem projectFileSystem) { using (IServiceScope scope = _serviceScopeFactory.CreateScope()) { IServiceProvider serviceProvider = scope.ServiceProvider; // See RazorViewCompiler.CompileAndEmit() RazorProjectEngine projectEngine = serviceProvider.GetRequiredService <RazorProjectEngine>(); RazorCodeDocument codeDocument = projectEngine.Process(projectItem); RazorCSharpDocument cSharpDocument = codeDocument.GetCSharpDocument(); if (cSharpDocument.Diagnostics.Count > 0) { throw (Exception)CreateCompilationFailedException.Invoke( null, new object[] { codeDocument, cSharpDocument.Diagnostics }); } // Use the RazorViewCompiler to finish compiling the view for consistency with layouts IViewCompilerProvider viewCompilerProvider = serviceProvider.GetRequiredService <IViewCompilerProvider>(); IViewCompiler viewCompiler = viewCompilerProvider.GetCompiler(); Assembly assembly = (Assembly)CompileAndEmitMethod.Invoke( viewCompiler, new object[] { codeDocument, cSharpDocument.GeneratedCode }); // Get the runtime item RazorCompiledItemLoader compiledItemLoader = new RazorCompiledItemLoader(); RazorCompiledItem compiledItem = compiledItemLoader.LoadItems(assembly).SingleOrDefault(); return(new CompilationResult(compiledItem)); } }
public PlatoRazorPageFactoryProvider( IViewCompilerProvider viewCompilerProvider, ISingletonCache <CompiledViewDescriptor> complierCache) { _viewCompilerProvider = viewCompilerProvider; _complierCache = complierCache; }
public DataModelController(DataModel dataModel , IViewCompilerProvider viewCompilerProvider , HtmlEncoder htmlEncoder ) { _dataModel = dataModel; _viewCompilerProvider = viewCompilerProvider; _htmlEncoder = htmlEncoder; }
public DefaultPageLoader( IEnumerable <IPageApplicationModelProvider> applicationModelProviders, IViewCompilerProvider viewCompilerProvider, ActionEndpointFactory endpointFactory, IOptions <RazorPagesOptions> pageOptions, IOptions <MvcOptions> mvcOptions) { _viewCompilerProvider = viewCompilerProvider; _endpointFactory = endpointFactory; _compiledPageActionDescriptorFactory = new CompiledPageActionDescriptorFactory(applicationModelProviders, mvcOptions.Value, pageOptions.Value); }
public DefaultPageLoader( IEnumerable <IPageApplicationModelProvider> applicationModelProviders, IViewCompilerProvider viewCompilerProvider, IOptions <RazorPagesOptions> pageOptions, IOptions <MvcOptions> mvcOptions) { _applicationModelProviders = applicationModelProviders .OrderBy(p => p.Order) .ToArray(); _viewCompilerProvider = viewCompilerProvider; _conventions = pageOptions.Value.Conventions; _globalFilters = mvcOptions.Value.Filters; }
public DefaultPageLoader( IEnumerable <IPageApplicationModelProvider> applicationModelProviders, IViewCompilerProvider viewCompilerProvider, ActionEndpointFactory endpointFactory, IOptions <RazorPagesOptions> pageOptions, IOptions <MvcOptions> mvcOptions) { _applicationModelProviders = applicationModelProviders .OrderBy(p => p.Order) .ToArray(); _viewCompilerProvider = viewCompilerProvider; _endpointFactory = endpointFactory; _conventions = pageOptions.Value.Conventions ?? throw new ArgumentNullException(nameof(RazorPagesOptions.Conventions)); _globalFilters = mvcOptions.Value.Filters; }
public MvcModuleSetup(ApplicationPartManager partManager, IReferenceLoader referenceLoader, IPluginsAssemblyLoadContexts pluginsLoadContexts, DynamicChangeTokenProvider dynamicChangeTokenProvider, INotificationRegister notificationRegister, IOptions <PluginOptions> options, IWebHostEnvironment webHostEnvironment, IRazorViewEngine razorViewEngine, IViewCompilerProvider viewCompiler) { _partManager = partManager; _referenceLoader = referenceLoader; _pluginsLoadContexts = pluginsLoadContexts; _dynamicChangeTokenProvider = dynamicChangeTokenProvider; _notificationRegister = notificationRegister; _pluginOptions = options.Value; _env = webHostEnvironment; //_baseDirectory = AppContext.BaseDirectory; _baseDirectory = _env.ContentRootPath; _razorViewEngine = razorViewEngine; _viewCompiler = viewCompiler; }
public DefaultPageLoader( IActionDescriptorCollectionProvider actionDescriptorCollectionProvider, IEnumerable <IPageApplicationModelProvider> applicationModelProviders, IViewCompilerProvider viewCompilerProvider, ActionEndpointFactory endpointFactory, IOptions <RazorPagesOptions> pageOptions, IOptions <MvcOptions> mvcOptions) { _collectionProvider = actionDescriptorCollectionProvider; _applicationModelProviders = applicationModelProviders .OrderBy(p => p.Order) .ToArray(); _viewCompilerProvider = viewCompilerProvider; _endpointFactory = endpointFactory; _conventions = pageOptions.Value.Conventions; _globalFilters = mvcOptions.Value.Filters; }
public RazorHotReload( IRazorViewEngine razorViewEngine, IRazorPageActivator razorPageActivator, ITagHelperFactory tagHelperFactory, IViewCompilerProvider viewCompilerProvider, ITagHelperComponentPropertyActivator tagHelperComponentPropertyActivator, ApplicationPartManager applicationPartManager) { // For Razor view services, use the service locator pattern because they views not be registered by default. _razorCompiledItemFeatureProvider = applicationPartManager.FeatureProviders.OfType <RazorCompiledItemFeatureProvider>().FirstOrDefault(); if (viewCompilerProvider is DefaultViewCompiler defaultViewCompiler) { _defaultViewCompiler = defaultViewCompiler; } if (razorViewEngine.GetType() == typeof(RazorViewEngine)) { _razorViewEngine = (RazorViewEngine)razorViewEngine; } if (razorPageActivator.GetType() == typeof(RazorPageActivator)) { _razorPageActivator = (RazorPageActivator)razorPageActivator; } if (tagHelperFactory is DefaultTagHelperFactory defaultTagHelperFactory) { _defaultTagHelperFactory = defaultTagHelperFactory; } if (tagHelperComponentPropertyActivator is TagHelperComponentPropertyActivator defaultTagHelperComponentPropertyActivator) { _tagHelperComponentPropertyActivator = defaultTagHelperComponentPropertyActivator; } }
/// <summary> /// Initializes a new instance of <see cref="DefaultRazorPageFactoryProvider"/>. /// </summary> /// <param name="viewCompilerProvider">The <see cref="IViewCompilerProvider"/>.</param> public DefaultRazorPageFactoryProvider(IViewCompilerProvider viewCompilerProvider) { _viewCompilerProvider = viewCompilerProvider; }