/// <summary> /// Initializes a new instance of the <see cref="RazorViewEngine" />. /// </summary> public RazorViewEngine( IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorViewEngineOptions> optionsAccessor, ILoggerFactory loggerFactory) { _options = optionsAccessor.Value; if (_options.ViewLocationFormats.Count == 0) { throw new ArgumentException( Resources.FormatViewLocationFormatsIsRequired(nameof(RazorViewEngineOptions.ViewLocationFormats)), nameof(optionsAccessor)); } if (_options.AreaViewLocationFormats.Count == 0) { throw new ArgumentException( Resources.FormatViewLocationFormatsIsRequired(nameof(RazorViewEngineOptions.AreaViewLocationFormats)), nameof(optionsAccessor)); } _pageFactory = pageFactory; _pageActivator = pageActivator; _htmlEncoder = htmlEncoder; _logger = loggerFactory.CreateLogger <RazorViewEngine>(); ViewLookupCache = new MemoryCache(new MemoryCacheOptions { CompactOnMemoryPressure = false }); }
/// <summary> /// /// </summary> /// <param name="engine"></param> /// <param name="cSharpCompiler"></param> /// <param name="applicationPartManager"></param> /// <param name="tempDataDictionaryFactory"></param> /// <param name="razorViewEngineFileProviderAccessor"></param> /// <param name="razorPageActivator"></param> /// <param name="htmlEncoder"></param> /// <param name="razorPageFactoryProvider"></param> /// <param name="httpContextAccessor"></param> /// <param name="projectCacheProvider"></param> /// <param name="loggerFactory"></param> /// <param name="razorEngineOptions"></param> /// <param name="mvcViewOptions"></param> /// <param name="diagnosticSource"></param> public DynamicRazorEngine(RazorEngine engine, CSharpCompiler cSharpCompiler, ApplicationPartManager applicationPartManager, ITempDataDictionaryFactory tempDataDictionaryFactory, IRazorViewEngineFileProviderAccessor razorViewEngineFileProviderAccessor, IRazorPageActivator razorPageActivator, HtmlEncoder htmlEncoder, IRazorPageFactoryProvider razorPageFactoryProvider, IHttpContextAccessor httpContextAccessor, IDynamicRazorProjectCacheProvider projectCacheProvider, ILoggerFactory loggerFactory, IOptions <RazorViewEngineOptions> razorEngineOptions, IOptions <MvcViewOptions> mvcViewOptions, DiagnosticSource diagnosticSource, IServiceProvider serviceProvider) { _engine = engine; _tempDataDictionaryFactory = tempDataDictionaryFactory; _razorViewEngineFileProviderAccessor = razorViewEngineFileProviderAccessor; _cSharpCompiler = cSharpCompiler; _razorEngineOptions = razorEngineOptions; _applicationPartManager = applicationPartManager; _loggerFactory = loggerFactory; _razorPageActivator = razorPageActivator; _htmlEncoder = htmlEncoder; _httpContextAccessor = httpContextAccessor; _projectCacheProvider = projectCacheProvider; _diagnosticSource = diagnosticSource; _mvcViewOptions = mvcViewOptions; _razorPageFactoryProvider = razorPageFactoryProvider; _serviceProvider = serviceProvider; }
/// <summary> /// Gets the view for an input document (which is different than the view for a layout, partial, or /// other indirect view because it's not necessarily on disk or in the file system). /// </summary> private IView GetViewFromStream( string relativePath, Stream stream, string viewStartLocation, string layoutLocation, IRazorViewEngine viewEngine, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IRazorPageFactoryProvider pageFactoryProvider, IFileProvider rootFileProvider, IRazorCompilationService razorCompilationService) { IEnumerable <string> viewStartLocations = viewStartLocation != null ? new [] { viewStartLocation } : ViewHierarchyUtility.GetViewStartLocations(relativePath); List <IRazorPage> viewStartPages = viewStartLocations .Select(pageFactoryProvider.CreateFactory) .Where(x => x.Success) .Select(x => x.RazorPageFactory()) .Reverse() .ToList(); IRazorPage page = GetPageFromStream(relativePath, viewStartLocation, layoutLocation, stream, rootFileProvider, razorCompilationService); if (layoutLocation != null) { page.Layout = layoutLocation; } return(new RazorView(viewEngine, pageActivator, viewStartPages, page, htmlEncoder)); }
/// <summary> /// Initializes a new instance of the <see cref="RazorViewEngine" />. /// </summary> public RazorViewEngine( IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorViewEngineOptions> optionsAccessor, RazorProject razorProject, ILoggerFactory loggerFactory, DiagnosticSource diagnosticSource) { _options = optionsAccessor.Value; if (_options.ViewLocationFormats.Count == 0) { throw new ArgumentException( Resources.FormatViewLocationFormatsIsRequired(nameof(RazorViewEngineOptions.ViewLocationFormats)), nameof(optionsAccessor)); } if (_options.AreaViewLocationFormats.Count == 0) { throw new ArgumentException( Resources.FormatViewLocationFormatsIsRequired(nameof(RazorViewEngineOptions.AreaViewLocationFormats)), nameof(optionsAccessor)); } _pageFactory = pageFactory; _pageActivator = pageActivator; _htmlEncoder = htmlEncoder; _logger = loggerFactory.CreateLogger <RazorViewEngine>(); _razorProject = razorProject; _diagnosticSource = diagnosticSource; ViewLookupCache = new MemoryCache(new MemoryCacheOptions()); }
public PageActionInvokerProvider( IPageLoader loader, IPageFactoryProvider pageFactoryProvider, IPageModelFactoryProvider modelFactoryProvider, IRazorPageFactoryProvider razorPageFactoryProvider, IActionDescriptorCollectionProvider collectionProvider, IEnumerable <IFilterProvider> filterProviders, ParameterBinder parameterBinder, IModelMetadataProvider modelMetadataProvider, ITempDataDictionaryFactory tempDataFactory, IOptions <MvcOptions> mvcOptions, IOptions <HtmlHelperOptions> htmlHelperOptions, IPageHandlerMethodSelector selector, RazorProject razorProject, DiagnosticSource diagnosticSource, ILoggerFactory loggerFactory) { _loader = loader; _pageFactoryProvider = pageFactoryProvider; _modelFactoryProvider = modelFactoryProvider; _razorPageFactoryProvider = razorPageFactoryProvider; _collectionProvider = collectionProvider; _filterProviders = filterProviders.ToArray(); _valueProviderFactories = mvcOptions.Value.ValueProviderFactories.ToArray(); _parameterBinder = parameterBinder; _modelMetadataProvider = modelMetadataProvider; _tempDataFactory = tempDataFactory; _htmlHelperOptions = htmlHelperOptions.Value; _selector = selector; _razorProject = razorProject; _diagnosticSource = diagnosticSource; _logger = loggerFactory.CreateLogger <PageActionInvoker>(); }
/// <summary> /// Initializes a new instance of the <see cref="RazorViewEngine" />. /// </summary> public CustomRazorViewEngine( IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorViewEngineOptions> optionsAccessor, ILoggerFactory loggerFactory, DiagnosticListener diagnosticListener) { _options = optionsAccessor.Value; if (_options.ViewLocationFormats.Count == 0) { throw new ArgumentException( $"required {nameof(RazorViewEngineOptions.ViewLocationFormats)}", nameof(optionsAccessor)); } if (_options.AreaViewLocationFormats.Count == 0) { throw new ArgumentException( $"required {nameof(RazorViewEngineOptions.AreaViewLocationFormats)}", nameof(optionsAccessor)); } _pageFactory = pageFactory; _pageActivator = pageActivator; _htmlEncoder = htmlEncoder; _logger = loggerFactory.CreateLogger <RazorViewEngine>(); _diagnosticListener = diagnosticListener; ViewLookupCache = new MemoryCache(new MemoryCacheOptions()); }
/// <summary> /// Initializes a new instance of the <see cref="RazorViewEngine" />. /// </summary> public RazorViewEngine( IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions<RazorViewEngineOptions> optionsAccessor, ILoggerFactory loggerFactory) { _options = optionsAccessor.Value; if (_options.ViewLocationFormats.Count == 0) { throw new ArgumentException( Resources.FormatViewLocationFormatsIsRequired(nameof(RazorViewEngineOptions.ViewLocationFormats)), nameof(optionsAccessor)); } if (_options.AreaViewLocationFormats.Count == 0) { throw new ArgumentException( Resources.FormatViewLocationFormatsIsRequired(nameof(RazorViewEngineOptions.AreaViewLocationFormats)), nameof(optionsAccessor)); } _pageFactory = pageFactory; _pageActivator = pageActivator; _htmlEncoder = htmlEncoder; _logger = loggerFactory.CreateLogger<RazorViewEngine>(); ViewLookupCache = new MemoryCache(new MemoryCacheOptions { CompactOnMemoryPressure = false }); }
public SimpleRazorViewEngine(IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorViewEngineOptions> optionsAccessor, ILoggerFactory loggerFactory) : base(pageFactory, pageActivator, htmlEncoder, optionsAccessor, loggerFactory) { optionsAccessor.Value.ViewLocationFormats.Clear(); optionsAccessor.Value.ViewLocationFormats.Add("~/wwwroot/app/components/{1}/{0}.html"); optionsAccessor.Value.ViewLocationFormats.Add("~/wwwroot/app/{1}/{0}.html"); optionsAccessor.Value.ViewLocationFormats.Add("~/wwwroot/app/{0}.html"); }
/// <summary> /// Initializes a new instance of the <see cref="MinifiedRazorViewEngine" /> class. /// </summary> /// <param name="pageFactory">The page factory used for creating <see cref="IRazorPage"/> instances.</param> public MinifiedRazorViewEngine( IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorViewEngineOptions> optionsAccessor, ILoggerFactory loggerFactory) : base(pageFactory, pageActivator, htmlEncoder, optionsAccessor, loggerFactory) { }
private static PageActionInvokerProvider CreateInvokerProvider( IPageLoader loader, IActionDescriptorCollectionProvider actionDescriptorProvider, IPageFactoryProvider pageProvider = null, IPageModelFactoryProvider modelProvider = null, IRazorPageFactoryProvider razorPageFactoryProvider = null, RazorProjectFileSystem fileSystem = null) { var tempDataFactory = new Mock <ITempDataDictionaryFactory>(); tempDataFactory .Setup(t => t.GetTempData(It.IsAny <HttpContext>())) .Returns((HttpContext context) => new TempDataDictionary(context, Mock.Of <ITempDataProvider>())); if (fileSystem == null) { fileSystem = Mock.Of <RazorProjectFileSystem>(); } var modelMetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(); var modelBinderFactory = TestModelBinderFactory.CreateDefault(); var mvcOptions = new MvcOptions { AllowValidatingTopLevelNodes = true, }; var parameterBinder = new ParameterBinder( modelMetadataProvider, TestModelBinderFactory.CreateDefault(), Mock.Of <IObjectModelValidator>(), Options.Create(mvcOptions), NullLoggerFactory.Instance); return(new PageActionInvokerProvider( loader, pageProvider ?? Mock.Of <IPageFactoryProvider>(), modelProvider ?? Mock.Of <IPageModelFactoryProvider>(), razorPageFactoryProvider ?? Mock.Of <IRazorPageFactoryProvider>(), actionDescriptorProvider, new IFilterProvider[0], parameterBinder, modelMetadataProvider, modelBinderFactory, tempDataFactory.Object, Options.Create(new MvcOptions()), Options.Create(new HtmlHelperOptions()), Mock.Of <IPageHandlerMethodSelector>(), fileSystem, new DiagnosticListener("Microsoft.AspNetCore"), NullLoggerFactory.Instance, new ActionResultTypeMapper())); }
//public CompositePrecompiledMvcEngine() { } /// <inheritdoc /> public CompositePrecompiledMvcEngine(IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorViewEngineOptions> optionsAccessor, RazorProjectFileSystem razorFileSystem, ILoggerFactory loggerFactory, DiagnosticSource diagnosticSource) : base(pageFactory, pageActivator, htmlEncoder, optionsAccessor, razorFileSystem, loggerFactory, diagnosticSource) { _pageActivator = pageActivator; _htmlEncoder = htmlEncoder; _diagnosticSource = diagnosticSource; }
public TemplateEngine( IRazorViewEngine engine, TemplateRazorEngine myEngine, IRazorPageFactoryProvider factoryProvider, IRazorPageActivator razorPageActivator, ITempDataProvider tempDataProvider, IServiceProvider serviceProvider) { _engine = engine; _tempDataProvider = tempDataProvider; _serviceProvider = serviceProvider; _myEngine = myEngine; }
public CustomRazorViewEngine( IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorViewEngineOptions> optionsAccessor, RazorProjectFileSystem razorFileSystem, ILoggerFactory loggerFactory, DiagnosticSource diagnosticSource) : base(pageFactory, pageActivator, htmlEncoder, optionsAccessor, razorFileSystem, loggerFactory, diagnosticSource) { }
/// <summary> /// Initializes a new instance of the RazorViewEngine /// </summary> public RazorViewEngine( IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorViewEngineOptions> optionsAccessor, RazorProjectFileSystem razorFileSystem, ILoggerFactory loggerFactory, DiagnosticSource diagnosticSource) #pragma warning disable CS0618 // Type or member is obsolete : this(pageFactory, pageActivator, htmlEncoder, optionsAccessor, (RazorProject)razorFileSystem, loggerFactory, diagnosticSource) #pragma warning restore CS0618 // Type or member is obsolete { }
public PlatoViewEngine( IRazorPageFactoryProvider pageFactory, IOptions <RazorViewEngineOptions> optionsAccessor, DiagnosticListener diagnosticListener, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder) { _diagnosticListener = diagnosticListener; _options = optionsAccessor.Value; _pageActivator = pageActivator; _pageFactory = pageFactory; _htmlEncoder = htmlEncoder; ViewLookupCache = new MemoryCache(new MemoryCacheOptions()); }
//IRazorViewEngine public CoreViewEngine( IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorViewEngineOptions> optionsAccessor, ILoggerFactory loggerFactory ) : base(pageFactory, pageActivator, htmlEncoder, optionsAccessor, loggerFactory) { //https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Razor/RazorViewEngine.cs // {0} represents the name of the view // {1} represents the name of the controller // {2} represents the name of the area }
public ModuleViewEngine(IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorViewEngineOptions> optionsAccessor, IOptions <ModuleViewEngineOptions> moduleOptionsAccessor, ILoggerFactory loggerFactory, DiagnosticListener diagnosticListener) : base(pageFactory, pageActivator, htmlEncoder, optionsAccessor, loggerFactory, diagnosticListener) { _options = moduleOptionsAccessor.Value; _pageFactory = pageFactory; _pageActivator = pageActivator; _htmlEncoder = htmlEncoder; _diagnosticListener = diagnosticListener; }
/// <summary> /// Initializes a new instance of the <see cref="RazorViewEngine" />. /// </summary> public MultiTemplateEngine( IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorViewEngineOptions> optionsAccessor, ILoggerFactory loggerFactory, RazorProject razorProject) { _options = optionsAccessor.Value; _pageFactory = pageFactory; _pageActivator = pageActivator; _htmlEncoder = htmlEncoder; _logger = loggerFactory.CreateLogger <RazorViewEngine>(); _razorProject = razorProject; ViewLookupCache = new MemoryCache(new MemoryCacheOptions()); }
//IRazorViewEngine public CoreViewEngine( IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions<RazorViewEngineOptions> optionsAccessor, ILoggerFactory loggerFactory ) :base(pageFactory, pageActivator, htmlEncoder, optionsAccessor, loggerFactory) { //https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNet.Mvc.Razor/RazorViewEngine.cs // {0} represents the name of the view // {1} represents the name of the controller // {2} represents the name of the area }
public ModulesRazorPageFactoryProvider( IRazorCompilationService razorCompilationService, ICompilerCacheProvider compilerCacheProvider, IHostingEnvironment moduleEnv, IRootServiceProvider rootServices) { _appProvider = rootServices.GetService <IRazorPageFactoryProvider>(); if (_appProvider == null) { throw new ArgumentNullException(nameof(_appProvider)); } _defaultProvider = new DefaultRazorPageFactoryProvider(razorCompilationService, compilerCacheProvider); _moduleEnv = moduleEnv; _rootEnv = rootServices.GetRequiredService <IHostingEnvironment>(); }
private static PageActionInvokerProvider CreateInvokerProvider( PageLoader loader, IPageFactoryProvider pageProvider = null, IPageModelFactoryProvider modelProvider = null, IRazorPageFactoryProvider razorPageFactoryProvider = null, MvcOptions mvcOptions = null) { var tempDataFactory = new Mock <ITempDataDictionaryFactory>(); tempDataFactory .Setup(t => t.GetTempData(It.IsAny <HttpContext>())) .Returns((HttpContext context) => new TempDataDictionary(context, Mock.Of <ITempDataProvider>())); var modelMetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(); var modelBinderFactory = TestModelBinderFactory.CreateDefault(); mvcOptions = mvcOptions ?? new MvcOptions(); var parameterBinder = new ParameterBinder( modelMetadataProvider, TestModelBinderFactory.CreateDefault(), Mock.Of <IObjectModelValidator>(), Options.Create(mvcOptions), NullLoggerFactory.Instance); var cache = new PageActionInvokerCache( pageProvider ?? Mock.Of <IPageFactoryProvider>(), modelProvider ?? Mock.Of <IPageModelFactoryProvider>(), razorPageFactoryProvider ?? Mock.Of <IRazorPageFactoryProvider>(), new IFilterProvider[0], parameterBinder, modelMetadataProvider, modelBinderFactory, Options.Create(mvcOptions)); return(new PageActionInvokerProvider( loader, cache, modelMetadataProvider, tempDataFactory.Object, Options.Create(mvcOptions), Options.Create(new MvcViewOptions()), Mock.Of <IPageHandlerMethodSelector>(), new DiagnosticListener("Microsoft.AspNetCore"), NullLoggerFactory.Instance, new ActionResultTypeMapper())); }
/// <summary> /// Initializes a new instance of the <see cref="RazorViewEngine" />. /// </summary> public RazorViewEngine( IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions<RazorViewEngineOptions> optionsAccessor, ILoggerFactory loggerFactory) { _pageFactory = pageFactory; _pageActivator = pageActivator; _viewLocationExpanders = optionsAccessor.Value.ViewLocationExpanders; _htmlEncoder = htmlEncoder; _logger = loggerFactory.CreateLogger<RazorViewEngine>(); ViewLookupCache = new MemoryCache(new MemoryCacheOptions { CompactOnMemoryPressure = false }); }
/// <summary> /// Initializes a new instance of the <see cref="RazorViewEngine" />. /// </summary> public MultiTemplateEngine( IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions<RazorViewEngineOptions> optionsAccessor, ILoggerFactory loggerFactory) { _options = optionsAccessor.Value; _pageFactory = pageFactory; _pageActivator = pageActivator; _htmlEncoder = htmlEncoder; _logger = loggerFactory.CreateLogger<RazorViewEngine>(); ViewLookupCache = new MemoryCache(new MemoryCacheOptions { CompactOnMemoryPressure = false }); }
public PageActionInvokerCache( IPageFactoryProvider pageFactoryProvider, IPageModelFactoryProvider modelFactoryProvider, IRazorPageFactoryProvider razorPageFactoryProvider, IEnumerable <IFilterProvider> filterProviders, ParameterBinder parameterBinder, IModelMetadataProvider modelMetadataProvider, IModelBinderFactory modelBinderFactory) { _pageFactoryProvider = pageFactoryProvider; _modelFactoryProvider = modelFactoryProvider; _modelBinderFactory = modelBinderFactory; _razorPageFactoryProvider = razorPageFactoryProvider; _filterProviders = filterProviders.ToArray(); _parameterBinder = parameterBinder; _modelMetadataProvider = modelMetadataProvider; }
private static PageActionInvokerProvider CreateInvokerProvider( IPageLoader loader, IActionDescriptorCollectionProvider actionDescriptorProvider, IPageFactoryProvider pageProvider = null, IPageModelFactoryProvider modelProvider = null, IRazorPageFactoryProvider razorPageFactoryProvider = null, RazorProject razorProject = null) { var tempDataFactory = new Mock <ITempDataDictionaryFactory>(); tempDataFactory .Setup(t => t.GetTempData(It.IsAny <HttpContext>())) .Returns((HttpContext context) => new TempDataDictionary(context, Mock.Of <ITempDataProvider>())); if (razorProject == null) { razorProject = Mock.Of <RazorProject>(); } var modelMetadataProvider = TestModelMetadataProvider.CreateDefaultProvider(); var parameterBinder = new ParameterBinder( modelMetadataProvider, TestModelBinderFactory.CreateDefault(), Mock.Of <IModelValidatorProvider>()); return(new PageActionInvokerProvider( loader, pageProvider ?? Mock.Of <IPageFactoryProvider>(), modelProvider ?? Mock.Of <IPageModelFactoryProvider>(), razorPageFactoryProvider ?? Mock.Of <IRazorPageFactoryProvider>(), actionDescriptorProvider, new IFilterProvider[0], parameterBinder, modelMetadataProvider, tempDataFactory.Object, new TestOptionsManager <MvcOptions>(), new TestOptionsManager <HtmlHelperOptions>(), Mock.Of <IPageHandlerMethodSelector>(), razorProject, new DiagnosticListener("Microsoft.AspNetCore"), NullLoggerFactory.Instance)); }
public MyPageActionInvokerProvider( IPageLoader loader, IPageFactoryProvider pageFactoryProvider, IPageModelFactoryProvider modelFactoryProvider, IRazorPageFactoryProvider razorPageFactoryProvider, IActionDescriptorCollectionProvider collectionProvider, IEnumerable <IFilterProvider> filterProviders, ParameterBinder parameterBinder, IModelMetadataProvider modelMetadataProvider, IModelBinderFactory modelBinderFactory, ITempDataDictionaryFactory tempDataFactory, IOptions <MvcOptions> mvcOptions, IOptions <HtmlHelperOptions> htmlHelperOptions, IPageHandlerMethodSelector selector, RazorProjectFileSystem razorFileSystem, DiagnosticSource diagnosticSource, ILoggerFactory loggerFactory, IActionResultTypeMapper mapper) : base(loader, pageFactoryProvider, modelFactoryProvider, razorPageFactoryProvider, collectionProvider, filterProviders, parameterBinder, modelMetadataProvider, modelBinderFactory, tempDataFactory, mvcOptions, htmlHelperOptions, selector, razorFileSystem, diagnosticSource, loggerFactory, mapper) { }
public RazorMultiViewEngine(IHttpContextAccessor contextAccessor, IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorMultiViewEngineOptions> optionsAccessor, DiagnosticListener diagnosticListener) { this.pageFactory = pageFactory ?? throw new ArgumentNullException(nameof(pageFactory)); this.pageActivator = pageActivator ?? throw new ArgumentNullException(nameof(pageActivator)); this.htmlEncoder = htmlEncoder ?? throw new ArgumentNullException(nameof(htmlEncoder)); this.options = optionsAccessor?.Value ?? throw new ArgumentNullException(nameof(optionsAccessor)); this.diagnosticListener = diagnosticListener ?? throw new ArgumentNullException(nameof(diagnosticListener)); if (contextAccessor is null) { throw new ArgumentNullException(nameof(contextAccessor)); } this.ViewLookupCache = new MultiTenantMemoryCache(contextAccessor, options.HttpContextItemsKey); }
public PageActionInvokerProvider( IPageLoader loader, IPageFactoryProvider pageFactoryProvider, IPageModelFactoryProvider modelFactoryProvider, IRazorPageFactoryProvider razorPageFactoryProvider, IActionDescriptorCollectionProvider collectionProvider, IEnumerable <IFilterProvider> filterProviders, ParameterBinder parameterBinder, IModelMetadataProvider modelMetadataProvider, IModelBinderFactory modelBinderFactory, ITempDataDictionaryFactory tempDataFactory, IOptions <MvcOptions> mvcOptions, IOptions <HtmlHelperOptions> htmlHelperOptions, IPageHandlerMethodSelector selector, DiagnosticListener diagnosticListener, ILoggerFactory loggerFactory, IActionResultTypeMapper mapper, IActionContextAccessor actionContextAccessor) { _loader = loader; _pageFactoryProvider = pageFactoryProvider; _modelFactoryProvider = modelFactoryProvider; _modelBinderFactory = modelBinderFactory; _razorPageFactoryProvider = razorPageFactoryProvider; _collectionProvider = collectionProvider; _filterProviders = filterProviders.ToArray(); _valueProviderFactories = mvcOptions.Value.ValueProviderFactories.ToArray(); _parameterBinder = parameterBinder; _modelMetadataProvider = modelMetadataProvider; _tempDataFactory = tempDataFactory; _mvcOptions = mvcOptions.Value; _htmlHelperOptions = htmlHelperOptions.Value; _selector = selector; _diagnosticListener = diagnosticListener; _logger = loggerFactory.CreateLogger <PageActionInvoker>(); _mapper = mapper; _actionContextAccessor = actionContextAccessor ?? ActionContextAccessor.Null; }
public PageActionInvokerProvider( IPageLoader loader, IPageFactoryProvider pageFactoryProvider, IPageModelFactoryProvider modelFactoryProvider, IRazorPageFactoryProvider razorPageFactoryProvider, IActionDescriptorCollectionProvider collectionProvider, IEnumerable <IFilterProvider> filterProviders, ParameterBinder parameterBinder, IModelMetadataProvider modelMetadataProvider, IModelBinderFactory modelBinderFactory, ITempDataDictionaryFactory tempDataFactory, IOptions <MvcOptions> mvcOptions, IOptions <HtmlHelperOptions> htmlHelperOptions, IPageHandlerMethodSelector selector, DiagnosticListener diagnosticListener, ILoggerFactory loggerFactory, IActionResultTypeMapper mapper) : this( loader, pageFactoryProvider, modelFactoryProvider, razorPageFactoryProvider, collectionProvider, filterProviders, parameterBinder, modelMetadataProvider, modelBinderFactory, tempDataFactory, mvcOptions, htmlHelperOptions, selector, diagnosticListener, loggerFactory, mapper, actionContextAccessor : null) { }
/// <summary> /// Initializes a new instance of the <see cref="FWRazorViewEngine" />. /// </summary> public FWRazorViewEngine(IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorViewEngineOptions> optionsAccessor, RazorProject razorProject, ILoggerFactory loggerFactory, DiagnosticSource diagnosticSource) { _engine = new RazorViewEngine(pageFactory, pageActivator, htmlEncoder, optionsAccessor, razorProject, loggerFactory, diagnosticSource); }
public RazorViewEngine(IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorViewEngineOptions> optionsAccessor, RazorProject razorProject, ILoggerFactory loggerFactory, DiagnosticSource diagnosticSource) { _RazorViewEngine = new Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine(pageFactory, pageActivator, htmlEncoder, optionsAccessor, razorProject, loggerFactory, diagnosticSource); }
private TestableRazorViewEngine CreateViewEngine( IRazorPageFactoryProvider pageFactory = null, IEnumerable<IViewLocationExpander> expanders = null) { pageFactory = pageFactory ?? Mock.Of<IRazorPageFactoryProvider>(); return new TestableRazorViewEngine( pageFactory, GetOptionsAccessor(expanders)); }
public IEnumerable <IDocument> Execute(IReadOnlyList <IDocument> inputs, IExecutionContext context) { // Register all the MVC and Razor services // In the future, if DI is implemented for all Wyam, the IExecutionContext would be registered as a service // and the IHostingEnviornment would be registered as transient with the execution context provided in ctor IServiceCollection serviceCollection = new ServiceCollection(); IMvcCoreBuilder builder = serviceCollection .AddMvcCore() .AddRazorViewEngine(); builder.PartManager.FeatureProviders.Add(new MetadataReferenceFeatureProvider(context)); serviceCollection.Configure <RazorViewEngineOptions>(options => { options.ViewLocationExpanders.Add(new ViewLocationExpander()); }); serviceCollection .AddSingleton <ILoggerFactory, TraceLoggerFactory>() .AddSingleton <DiagnosticSource, SilentDiagnosticSource>() .AddSingleton <IHostingEnvironment, HostingEnvironment>() .AddSingleton <ObjectPoolProvider, DefaultObjectPoolProvider>() .AddSingleton <IExecutionContext>(context) .AddSingleton <IBasePageTypeProvider>(new BasePageTypeProvider(_basePageType ?? typeof(RazorPage))) .AddScoped <IMvcRazorHost, RazorHost>(); IServiceProvider services = serviceCollection.BuildServiceProvider(); // Eliminate input documents that we shouldn't process List <IDocument> validInputs = inputs .Where(x => _ignorePrefix == null || !x.ContainsKey(Keys.SourceFileName) || !x.FilePath(Keys.SourceFileName).FullPath.StartsWith(_ignorePrefix)) .ToList(); // Compile and evaluate the pages in parallel IServiceScopeFactory scopeFactory = services.GetRequiredService <IServiceScopeFactory>(); return(validInputs.AsParallel().Select(input => { Trace.Verbose("Compiling Razor for {0}", input.SourceString()); using (var scope = scopeFactory.CreateScope()) { // Get services IRazorViewEngine viewEngine = services.GetRequiredService <IRazorViewEngine>(); IRazorPageActivator pageActivator = services.GetRequiredService <IRazorPageActivator>(); HtmlEncoder htmlEncoder = services.GetRequiredService <HtmlEncoder>(); IRazorPageFactoryProvider pageFactoryProvider = services.GetRequiredService <IRazorPageFactoryProvider>(); IRazorCompilationService razorCompilationService = services.GetRequiredService <IRazorCompilationService>(); IHostingEnvironment hostingEnviornment = services.GetRequiredService <IHostingEnvironment>(); // Compile the view string relativePath = GetRelativePath(input, context); FilePath viewStartLocationPath = _viewStartPath?.Invoke <FilePath>(input, context); string viewStartLocation = viewStartLocationPath != null ? GetRelativePath(viewStartLocationPath, context) : null; string layoutLocation = _layoutPath?.Invoke <FilePath>(input, context)?.FullPath; IView view; using (Stream stream = input.GetStream()) { view = GetViewFromStream(relativePath, stream, viewStartLocation, layoutLocation, viewEngine, pageActivator, htmlEncoder, pageFactoryProvider, hostingEnviornment.WebRootFileProvider, razorCompilationService); } // Render the view Trace.Verbose("Processing Razor for {0}", input.SourceString()); using (StringWriter output = new StringWriter()) { Microsoft.AspNetCore.Mvc.Rendering.ViewContext viewContext = GetViewContext(scope.ServiceProvider, view, input, context, output); viewContext.View.RenderAsync(viewContext).GetAwaiter().GetResult(); return context.GetDocument(input, output.ToString()); } } })); }
public TestableRazorViewEngine( IRazorPageFactoryProvider pageFactory, IOptions<RazorViewEngineOptions> optionsAccessor) : base(pageFactory, Mock.Of<IRazorPageActivator>(), new HtmlTestEncoder(), optionsAccessor, NullLoggerFactory.Instance) { }
//public AreaViewEngine() //{ // this.AreaViewLocationFormats = new[] {"~/Views/{2}/{1}/{0}.cshtml","~/Views/Shared/{0}.cshtml"}; // this.AreaMasterLocationFormats = new[] { "~/Views/Shared/{0}.cshtml" }; // this.AreaPartialViewLocationFormats = new[] { "~/Views/{2}/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml" }; // this.ViewLocationFormats = new[] { "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml" }; // this.MasterLocationFormats = new[] { "~/Views/Shared/{0}.cshtml" }; // this.PartialViewLocationFormats = new[] { "~/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml" }; //} public AreaViewEngine(IRazorPageFactoryProvider pageFactory, IRazorPageActivator pageActivator, HtmlEncoder htmlEncoder, IOptions <RazorViewEngineOptions> optionsAccessor, RazorProject razorProject, ILoggerFactory loggerFactory, DiagnosticSource diagnosticSource) : base(pageFactory, pageActivator, htmlEncoder, optionsAccessor, razorProject, loggerFactory, diagnosticSource) { /*add customized code between this region*/ /*add customized code between this region*/ }