示例#1
0
    /// <summary>
    /// Creates a new <see cref="ObjectResultExecutor"/>.
    /// </summary>
    /// <param name="formatterSelector">The <see cref="OutputFormatterSelector"/>.</param>
    /// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param>
    /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
    /// <param name="mvcOptions">Accessor to <see cref="MvcOptions"/>.</param>
    public ObjectResultExecutor(
        OutputFormatterSelector formatterSelector,
        IHttpResponseStreamWriterFactory writerFactory,
        ILoggerFactory loggerFactory,
        IOptions <MvcOptions> mvcOptions)
    {
        if (formatterSelector == null)
        {
            throw new ArgumentNullException(nameof(formatterSelector));
        }

        if (writerFactory == null)
        {
            throw new ArgumentNullException(nameof(writerFactory));
        }

        if (loggerFactory == null)
        {
            throw new ArgumentNullException(nameof(loggerFactory));
        }

        FormatterSelector = formatterSelector;
        WriterFactory     = writerFactory.CreateWriter;
        Logger            = loggerFactory.CreateLogger <ObjectResultExecutor>();
    }
 public ConvertViewResultToObjectResultAttributeImpl(OutputFormatterSelector formatterSelector, ILoggerFactory loggerFactory, IOptions <MvcOptions> mvcOptions, IOptions <ApiBehaviorOptions> apiBehaviorOptions, bool enabled)
 {
     _logger             = loggerFactory.CreateLogger <ConvertViewResultToObjectResultAttribute>();
     _mvcOptions         = mvcOptions.Value;
     _apiBehaviorOptions = apiBehaviorOptions.Value;
     _enabled            = enabled;
 }
示例#3
0
 public MiruObjectResultExecutor(
     OutputFormatterSelector formatterSelector,
     IHttpResponseStreamWriterFactory writerFactory,
     ILoggerFactory loggerFactory,
     IOptions <MvcOptions> mvcOptions) :
     base(formatterSelector, writerFactory, loggerFactory, mvcOptions)
 {
 }
示例#4
0
        public async Task Invoke(HttpContext context)
        {
            var aceeptHeaderEnricherContext = new AceeptHeaderEnricherContext(context, _options);

            foreach (var aceeptHeaderEnricher in _aceeptHeaderEnrichers.Where(a =>
                                                                              a.CanExecute(aceeptHeaderEnricherContext)))
            {
                aceeptHeaderEnricher.Execute(aceeptHeaderEnricherContext);
            }


            var acceptHeaders = new List <MediaTypeSegmentWithQuality>();

            AcceptHeaderParser.ParseAcceptHeader(context.Request.Headers[HeaderNames.Accept], acceptHeaders);
            context.Features.Set <IOutputFormatter>(OutputFormatterSelector.SelectFormatter(_options.Value.OutputFormatters.OfType <TextOutputFormatter>(), acceptHeaders));


            await _next(context);
        }
示例#5
0
        public HalObjectResultExecutor(
            IActionResultExecutor <ObjectResult> executor,
            IHttpResponseStreamWriterFactory writerFactory,
            OutputFormatterSelector formatterSelector,
            ILogger <HalObjectResultExecutor> logger)
        {
            this.executor = executor
                            ?? throw new ArgumentNullException(nameof(executor));

            this.formatterSelector = formatterSelector
                                     ?? throw new ArgumentNullException(nameof(formatterSelector));

            if (writerFactory == null)
            {
                throw new ArgumentNullException(nameof(writerFactory));
            }

            this.writerFactory = writerFactory.CreateWriter;

            this.logger = logger
                          ?? throw new ArgumentNullException(nameof(logger));
        }
示例#6
0
    public async Task InvokeAsync(HttpContext context,
                                  OutputFormatterSelector selector,
                                  IHttpResponseStreamWriterFactory writerFactory
                                  )
    {
        context.Response.StatusCode = 400;
        var response = new ErrorResponse {
            Errors = new Error[] {
                new Error {
                    Code        = "test",
                    Description = "test",
                    Meta        = new Dictionary <string, object> {
                        ["test"] = new Uri("http://go-fish")
                    }
                },
            }
        };

        var formatterContext = new OutputFormatterWriteContext(
            context, writerFactory.CreateWriter, typeof(ErrorResponse), response);

        var selectedFormatter = selector.SelectFormatter(formatterContext, Array.Empty <IOutputFormatter>(), new MediaTypeCollection());
        await selectedFormatter.WriteAsync(formatterContext);
    }
示例#7
0
 public ImageFilter(IOptions <MvcOptions> options, OutputFormatterSelector selector)
 {
     this.options  = options.Value;
     this.selector = selector;
 }
示例#8
0
 public LiepaResponseWrapper(OutputFormatterSelector formatterSelector,
                             IHttpResponseStreamWriterFactory writerFactory,
                             ILoggerFactory loggerFactory,
                             IOptions <MvcOptions> mvcOptions) : base(formatterSelector, writerFactory, loggerFactory, mvcOptions)
 {
 }
示例#9
0
 public QueryController(IEngine engine, IOptions <MvcOptions> options, OutputFormatterSelector selector)
 {
     this.engine   = engine;
     this.options  = options.Value;
     this.selector = selector;
 }
示例#10
0
 public ShaclController(IOptions <MvcOptions> options, OutputFormatterSelector selector)
 {
     this.options  = options.Value;
     this.selector = selector;
 }