public DefaultPageLoader(
            IOptions <RazorPagesOptions> options,
            RazorProject project,
            CSharpCompilationFactory compilationFactory,
            PageRazorEngineHost host,
            ITagHelperDescriptorResolver tagHelperDescriptorResolver)
        {
            _options            = options.Value;
            _project            = project;
            _compilationFactory = compilationFactory;
            _host = host;

            _tagHelperDescriptorResolver = tagHelperDescriptorResolver;

            _engine = RazorEngineBuilder.Build(builder =>
            {
                builder.Features.Add(new TagHelperFeature(_host.TagHelperDescriptorResolver));
                builder.Features.Add(new VirtualDocumentSyntaxTreePass());
                builder.Features.Add(new TagHelperBinderSyntaxTreePass());
                builder.Features.Add(new DefaultChunkTreeLoweringFeature(_host));

                builder.Features.Add(new PageDirectiveFeature()); // RazorPages-specific feature

                builder.Phases.Add(new DefaultSyntaxTreePhase());
                builder.Phases.Add(new DefaultChunkTreePhase());
                builder.Phases.Add(new DefaultCSharpSourceLoweringPhase(_host));
            });
        }
示例#2
0
        public DefaultPageLoader(
            IOptions <RazorPagesOptions> options,
            RazorProject project,
            CSharpCompilationFactory compilationFactory,
            PageRazorEngineHost host,
            ITagHelperDescriptorResolver tagHelperDescriptorResolver)
        {
            _options            = options.Value;
            _project            = project;
            _compilationFactory = compilationFactory;
            _host = host;

            _tagHelperDescriptorResolver = tagHelperDescriptorResolver;

            // TODO: Code smell, this is newed up in several locations. We should find a unified location for this.
            var attributeContext = new GeneratedTagHelperAttributeContext()
            {
                CreateModelExpressionMethodName     = "CreateModelExpression",
                ModelExpressionProviderPropertyName = "ModelExpressionProvider",
                ModelExpressionTypeName             = "Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExpression",
                ViewDataPropertyName = "ViewData",
            };

            _engine = RazorEngineBuilder.Build(builder =>
            {
                builder.Features.Add(new TagHelperFeature(_host.TagHelperDescriptorResolver));
                builder.Features.Add(new VirtualDocumentSyntaxTreePass());
                builder.Features.Add(new TagHelperBinderSyntaxTreePass());

                builder.Features.Add(new InstrumentationPass(_host));
                builder.Features.Add(new PreallocatedTagHelperAttributePass());

                // MVC specific features
                builder.Features.Add(new ModelExpressionAttributePass(attributeContext));
                builder.Features.Add(new InjectDirectiveRenderer(typeof(RazorInjectAttribute).FullName));

                builder.Features.Add(new DefaultChunkTreeLoweringFeature(_host));
                builder.Features.Add(new DefaultCSharpSourceLoweringFeature(_host));

                // Renderers
                builder.Features.Add(new RuntimeCSharpRenderer());
                builder.Features.Add(new PageStructureCSharpRenderer());

                builder.Features.Add(new PageDirectiveFeature()); // RazorPages-specific feature
                builder.Features.Add(new PagesPropertyInjectionPass());
                builder.Features.Add(new RazorDirectiveDiscoveryPass());

                builder.Phases.Add(new DefaultSyntaxTreePhase());
                builder.Phases.Add(new DefaultChunkTreePhase());

                // New Razor generation phases.
                builder.Phases.Add(new DefaultCSharpSourceLoweringPhase());
                builder.Phases.Add(new DefaultCSharpDocumentGenerationPhase(_host));

                // Uncomment the below line to force old-style view rendering.
                // builder.Phases.Add(new Razevolution.DefaultCSharpSourceLoweringPhase(_host));
            });
        }
示例#3
0
 public TestPageLoader(
     IOptions <RazorPagesOptions> options,
     RazorProject project,
     CSharpCompilationFactory compilationFactory,
     PageRazorEngineHost host,
     ITagHelperDescriptorResolver tagHelperDescriptorResolver)
     : base(options, project, compilationFactory, host, tagHelperDescriptorResolver)
 {
 }