public BsonInputFormatter(
     JsonSerializerSettings jsonSerializerSettings,
     ObjectPoolProvider objectPoolProvider)
 {
     _jsonSerializerSettings = jsonSerializerSettings;
     _objectPoolProvider = objectPoolProvider;
     SupportedEncodings.Add(Encoding.Unicode);
     SupportedEncodings.Add(Encoding.UTF8);
     SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/bson"));
 }
        public PooledHttpContextFactory(ObjectPoolProvider poolProvider, IHttpContextAccessor httpContextAccessor)
        {
            if (poolProvider == null)
            {
                throw new ArgumentNullException(nameof(poolProvider));
            }

            _builderPool = poolProvider.CreateStringBuilderPool();
            _httpContextAccessor = httpContextAccessor;
        }
 public HalInputFormatter(
     ILogger logger, 
     JsonSerializerSettings serializerSettings, 
     ArrayPool<char> charPool, 
     ObjectPoolProvider objectPoolProvider)
     : base(
           logger, 
           HalJsonSerializerSettingsProvider.AppendHalConverters(serializerSettings), 
           charPool, 
           objectPoolProvider)
 {
     SupportedMediaTypes.Add(new MediaTypeHeaderValue(HalJsonSerializerSettingsProvider.HalMediaType));
 }
示例#4
0
        public ResponseCachingKeyProvider(ObjectPoolProvider poolProvider, IOptions <ResponseCachingOptions> options)
        {
            if (poolProvider == null)
            {
                throw new ArgumentNullException(nameof(poolProvider));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _builderPool = poolProvider.CreateStringBuilderPool();
            _options     = options.Value;
        }
        /// <summary>
        /// Initializes a new <see cref="NewtonsoftJsonPatchInputFormatter"/> instance.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/>.</param>
        /// <param name="serializerSettings">
        /// The <see cref="JsonSerializerSettings"/>. Should be either the application-wide settings
        /// (<see cref="MvcNewtonsoftJsonOptions.SerializerSettings"/>) or an instance
        /// <see cref="JsonSerializerSettingsProvider.CreateSerializerSettings"/> initially returned.
        /// </param>
        /// <param name="charPool">The <see cref="ArrayPool{Char}"/>.</param>
        /// <param name="objectPoolProvider">The <see cref="ObjectPoolProvider"/>.</param>
        /// <param name="options">The <see cref="MvcOptions"/>.</param>
        /// <param name="jsonOptions">The <see cref="MvcNewtonsoftJsonOptions"/>.</param>
        public NewtonsoftJsonPatchInputFormatter(
            ILogger logger,
            JsonSerializerSettings serializerSettings,
            ArrayPool <char> charPool,
            ObjectPoolProvider objectPoolProvider,
            MvcOptions options,
            MvcNewtonsoftJsonOptions jsonOptions)
            : base(logger, serializerSettings, charPool, objectPoolProvider, options, jsonOptions)
        {
            // Clear all values and only include json-patch+json value.
            SupportedMediaTypes.Clear();

            SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationJsonPatch);
        }
示例#6
0
        public JsonMergePatchInputFormatter(
            ILogger logger,
            JsonSerializerSettings serializerSettings,
            ArrayPool <char> charPool,
            ObjectPoolProvider objectPoolProvider,
            JsonMergePatchOptions options)
            : base(logger, serializerSettings, charPool, objectPoolProvider)
        {
            this._charPool = new JsonArrayPool <char>(charPool);

            SupportedMediaTypes.Clear();
            SupportedMediaTypes.Add(JsonMergePatchMediaType);
            this._options = options;
        }
        public NewtonsoftJsonPatchInputFormatter(
            ILogger logger,
            JsonSerializerSettings serializerSettings,
            ArrayPool <char> charPool,
            ObjectPoolProvider objectPoolProvider,
            bool suppressInputFormatterBuffering,
            bool allowInputFormatterExceptionMessages)
            : base(logger, serializerSettings, charPool, objectPoolProvider, suppressInputFormatterBuffering, allowInputFormatterExceptionMessages)
        {
            // Clear all values and only include json-patch+json value.
            SupportedMediaTypes.Clear();

            SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationJsonPatch);
        }
示例#8
0
 public HypermediaApiMvcOptionsSetup(
     ILoggerFactory loggerFactory,
     IOptions <MvcJsonOptions> jsonOptions,
     ArrayPool <char> charPool,
     ObjectPoolProvider objectPoolProvider)
     : base((options) => ConfigureMvc(
                options,
                jsonOptions.Value.SerializerSettings,
                loggerFactory,
                charPool,
                objectPoolProvider,
                jsonOptions.Value))
 {
 }
 /// <summary>
 /// Creates a new <see cref="OutputCacheMiddleware"/>.
 /// </summary>
 /// <param name="next">The <see cref="RequestDelegate"/> representing the next middleware in the pipeline.</param>
 /// <param name="options">The options for this middleware.</param>
 /// <param name="loggerFactory">The <see cref="ILoggerFactory"/> used for logging.</param>
 /// <param name="outputCache">The <see cref="IOutputCacheStore"/> store.</param>
 /// <param name="poolProvider">The <see cref="ObjectPoolProvider"/> used for creating <see cref="ObjectPool"/> instances.</param>
 public OutputCacheMiddleware(
     RequestDelegate next,
     IOptions <OutputCacheOptions> options,
     ILoggerFactory loggerFactory,
     IOutputCacheStore outputCache,
     ObjectPoolProvider poolProvider
     )
     : this(
         next,
         options,
         loggerFactory,
         outputCache,
         new OutputCacheKeyProvider(poolProvider, options))
 {
 }
 public JsonMergePatchOptionsSetup(
     ILoggerFactory loggerFactory,
     IOptions <MvcJsonOptions> mvcJsonOptions,
     Lazy <IModelMetadataProvider> modelMetadataProvider,
     ArrayPool <char> charPool,
     ObjectPoolProvider objectPoolProvider,
     IOptions <JsonMergePatchOptions> jsonMergePatchOptions)
 {
     _loggerFactory         = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     _mvcJsonOptions        = mvcJsonOptions ?? throw new ArgumentNullException(nameof(mvcJsonOptions));
     _modelMetadataProvider = modelMetadataProvider ?? throw new ArgumentNullException(nameof(loggerFactory));
     _charPool              = charPool ?? throw new ArgumentNullException(nameof(charPool));
     _objectPoolProvider    = objectPoolProvider ?? throw new ArgumentNullException(nameof(objectPoolProvider));
     _jsonMergePatchOptions = jsonMergePatchOptions ?? throw new ArgumentNullException(nameof(jsonMergePatchOptions));
 }
        public HttpContextFactory(ObjectPoolProvider poolProvider, IOptions<FormOptions> formOptions, IHttpContextAccessor httpContextAccessor)
        {
            if (poolProvider == null)
            {
                throw new ArgumentNullException(nameof(poolProvider));
            }
            if (formOptions == null)
            {
                throw new ArgumentNullException(nameof(formOptions));
            }

            _builderPool = poolProvider.CreateStringBuilderPool();
            _formOptions = formOptions.Value;
            _httpContextAccessor = httpContextAccessor;
        }
        public RoutePatternBinderFactory(UrlEncoder encoder, ObjectPoolProvider objectPoolProvider)
        {
            if (encoder == null)
            {
                throw new ArgumentNullException(nameof(encoder));
            }

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

            _encoder = encoder;
            _pool    = objectPoolProvider.Create(new UriBuilderContextPooledObjectPolicy());
        }
示例#13
0
        public HttpContextFactory(ObjectPoolProvider poolProvider, IOptions <FormOptions> formOptions, IHttpContextAccessor httpContextAccessor)
        {
            if (poolProvider == null)
            {
                throw new ArgumentNullException(nameof(poolProvider));
            }
            if (formOptions == null)
            {
                throw new ArgumentNullException(nameof(formOptions));
            }

            _builderPool         = poolProvider.CreateStringBuilderPool();
            _formOptions         = formOptions.Value;
            _httpContextAccessor = httpContextAccessor;
        }
示例#14
0
 public NewtonsoftJsonMergePatchInputFormatter(
     ILogger logger,
     JsonSerializerSettings serializerSettings,
     ArrayPool <char> charPool,
     ObjectPoolProvider objectPoolProvider,
     MvcOptions mvcOptions,
     MvcNewtonsoftJsonOptions jsonOptions,
     Lazy <IModelMetadataProvider> lazyModelMetadataProvider,
     JsonMergePatchOptions jsonMergePatchOptions)
     : base(logger, serializerSettings, charPool, objectPoolProvider, mvcOptions, jsonOptions)
 {
     SupportedMediaTypes.Clear();
     SupportedMediaTypes.Add(JsonMergePatchMediaType);
     _modelMetadata         = new Lazy <ModelMetadata>(() => lazyModelMetadataProvider.Value.GetMetadataForType(typeof(JContainer)));
     _jsonMergePatchOptions = jsonMergePatchOptions;
 }
示例#15
0
        public JsonV1InputFormatter(ILogger logger,
                                    JsonSerializerSettings serializerSettings,
                                    ArrayPool <char> charPool,
                                    ObjectPoolProvider objectPoolProvider,
                                    MvcOptions options,
                                    MvcJsonOptions jsonOptions)
            : base(logger, serializerSettings, charPool, objectPoolProvider, options, jsonOptions)
        {
            _options = options;
            _jsonSerializerSettings = serializerSettings;
            _charPool = new JsonArrayPool <char>(charPool);

            SupportedMediaTypes.Clear();
            SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(MediaTypes.JsonV1));
            SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(MediaTypes.Problem));
        }
示例#16
0
    public static void UseHtmlEncodeJsonInputFormatter(this MvcOptions opts, ILogger <MvcOptions> logger,
                                                       ObjectPoolProvider objectPoolProvider)
    {
        //opts.InputFormatters.RemoveType<Microsoft.AspNetCore.Mvc.Formatters.NewtonsoftJsonInputFormatter>();

        //
        // var serializerSettings = new JsonSerializerSettings
        // {
        //     ContractResolver = new HtmlEncodeContractResolver(),
        //
        //
        // };
        //
        // var jsonInputFormatter = new NewtonsoftJsonInputFormatter(logger, serializerSettings,
        //     ArrayPool<char>.Shared, objectPoolProvider, opts, new MvcNewtonsoftJsonOptions());
        // opts.InputFormatters.Add(jsonInputFormatter);
    }
 /// <summary>
 /// Creates a new <see cref="ResponseCachingMiddleware"/>.
 /// </summary>
 /// <param name="next">The <see cref="RequestDelegate"/> representing the next middleware in the pipeline.</param>
 /// <param name="options">The options for this middleware.</param>
 /// <param name="loggerFactory">The <see cref="ILoggerFactory"/> used for logging.</param>
 /// <param name="poolProvider">The <see cref="ObjectPoolProvider"/> used for creating <see cref="ObjectPool"/> instances.</param>
 public ResponseCachingMiddleware(
     RequestDelegate next,
     IOptions <ResponseCachingOptions> options,
     ILoggerFactory loggerFactory,
     ObjectPoolProvider poolProvider)
     : this(
         next,
         options,
         loggerFactory,
         new ResponseCachingPolicyProvider(),
         new MemoryResponseCache(new MemoryCache(new MemoryCacheOptions
 {
     SizeLimit = options.Value.SizeLimit
 })),
         new ResponseCachingKeyProvider(poolProvider, options))
 {
 }
示例#18
0
        public FormattersMvcOptionsSetup(
            ILoggerFactory loggerFactory,
            IOptions <MvcNewtonsoftJsonOptions> jsonOptions,
            ArrayPool <char> charPool,
            ObjectPoolProvider objectPoolProvider)
        {
            if (jsonOptions == null)
            {
                throw new ArgumentNullException(nameof(jsonOptions));
            }

            _loggerFactory          = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            _jsonSerializerSettings = jsonOptions.Value.SerializerSettings;
            _charPool           = charPool ?? throw new ArgumentNullException(nameof(charPool));
            _objectPoolProvider = objectPoolProvider ?? throw new ArgumentNullException(nameof(objectPoolProvider));
            _mvcJsonOptions     = jsonOptions.Value;
        }
示例#19
0
        public CInputFormatter(
            IServiceProvider provider,
            ILogger logger,
            JsonSerializerSettings serializerSettings,
            ArrayPool <char> charPool,
            ObjectPoolProvider objectPoolProvider)
            : base(
                logger,
                serializerSettings,
                charPool,
                objectPoolProvider)
        {
            m_Provider = provider;

            SupportedMediaTypes.Clear();
            SupportedMediaTypes.Add(MEDIA_TYPE);
        }
示例#20
0
        public MessagingRoot(ObjectPoolProvider pooling,
                             MessagingSettings settings,
                             HandlerGraph handlers,
                             Forwarders forwarders,
                             IDurableMessagingFactory factory,
                             IChannelGraph channels,
                             ISubscriptionsRepository subscriptions,
                             IMessageLogger messageLogger,
                             IEnumerable <ISerializerFactory> serializers,
                             IEnumerable <IMessageDeserializer> readers,
                             IEnumerable <IMessageSerializer> writers,
                             ITransport[] transports,
                             IEnumerable <IMissingHandler> missingHandlers,
                             IEnumerable <IUriLookup> lookups, ITransportLogger transportLogger)
        {
            Settings         = settings;
            _handlers        = handlers;
            _transportLogger = transportLogger;
            Replies          = new ReplyWatcher();
            Factory          = factory;
            Channels         = channels;
            Transports       = transports;



            Lookup = new UriAliasLookup(lookups);


            Serialization = new MessagingSerializationGraph(pooling, settings, handlers, forwarders, serializers,
                                                            readers, writers);

            Logger = messageLogger;

            Pipeline = new HandlerPipeline(Serialization, handlers, Replies, Logger, missingHandlers,
                                           this);

            Workers = new WorkerQueue(Logger, Pipeline, settings);

            Router = new MessageRouter(Serialization, channels, subscriptions, handlers, Logger, Lookup, settings);

            // TODO -- ZOMG this is horrible, and I admit it.
            if (Factory is NulloDurableMessagingFactory)
            {
                Factory.As <NulloDurableMessagingFactory>().ScheduledJobs = ScheduledJobs;
            }
        }
示例#21
0
        protected SerializationGraph(ObjectPoolProvider pooling, JsonSerializerSettings jsonSettings,
                                     IEnumerable <ISerializerFactory> serializers,
                                     IEnumerable <IMessageDeserializer> readers, IEnumerable <IMessageSerializer> writers)
        {
            foreach (var serializer in serializers)
            {
                _serializers.SmartAdd(serializer.ContentType, serializer);
            }

            if (!_serializers.ContainsKey("application/json"))
            {
                var factory = new NewtonsoftSerializerFactory(jsonSettings, pooling);
                _serializers.SmartAdd("application/json", factory);
            }

            _readers.AddRange(readers);
            _writers.AddRange(writers);
        }
示例#22
0
        public ResponseCachingCustomMiddleware(
            RequestDelegate next,
            IOptions <ResponseCachingOptions> options,
            ILoggerFactory loggerFactory,
            ObjectPoolProvider poolProvider)
            : base(
                next,
                options,
                loggerFactory,
                poolProvider)
        {
            Options       = options;
            LoggerFactory = loggerFactory;
            PoolProvider  = poolProvider;

            loggerFactory.CreateLogger <ResponseCachingMiddleware>().LogInformation("Response Caching Middleware Initialised");
            Instance = this;
        }
示例#23
0
        public ResponseCachingKeyProvider(ObjectPoolProvider poolProvider, IOptions <ResponseCachingOptions> options)
        {
            var isEnabled = false;

            AppContext.TryGetSwitch(UseMethodPathCacheKeySwitch, out isEnabled);
            UseMethodPathCacheKey = isEnabled;

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

            _builderPool = poolProvider.CreateStringBuilderPool();
            _options     = options.Value;
        }
示例#24
0
        public static MvcOptions UseJsonV1InputFormatter(this MvcOptions options,
                                                         ILogger <MvcOptions> logger,
                                                         ObjectPoolProvider objectPoolProvider,
                                                         MvcJsonOptions jsonOptions,
                                                         JsonSerializerSettings serializerSettings)
        {
            options.InputFormatters.RemoveType <JsonInputFormatter>();

            JsonV1InputFormatter jsonV1InputFormatter = new JsonV1InputFormatter(logger,
                                                                                 serializerSettings,
                                                                                 ArrayPool <char> .Shared,
                                                                                 objectPoolProvider,
                                                                                 options,
                                                                                 jsonOptions);

            options.InputFormatters.Add(jsonV1InputFormatter);

            return(options);
        }
示例#25
0
        public StdioServer(TextReader input, ISharedTextWriter writer)
        {
            _input        = input;
            _writer       = writer;
            _cancellation = new CancellationTokenSource();

            _httpContextAccessor = new HttpContextAccessor();
            _objectPoolProvider  = new DefaultObjectPoolProvider();
            _formOptions         = Microsoft.Extensions.Options.Options.Create(new FormOptions());
            _httpContextFactory  = new HttpContextFactory(_objectPoolProvider, _formOptions, _httpContextAccessor);

            var features        = new FeatureCollection();
            var requestFeature  = new RequestFeature();
            var responseFeature = new ResponseFeature();

            features.Set <IHttpRequestFeature>(requestFeature);
            features.Set <IHttpResponseFeature>(responseFeature);
            Features = features;
        }
示例#26
0
        /// <summary>
        /// Initializes a new instance of <see cref="JsonInputFormatter"/>.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/>.</param>
        /// <param name="serializerSettings">
        /// The <see cref="JsonSerializerSettings"/>. Should be either the application-wide settings
        /// (<see cref="MvcJsonOptions.SerializerSettings"/>) or an instance
        /// <see cref="JsonSerializerSettingsProvider.CreateSerializerSettings"/> initially returned.
        /// </param>
        /// <param name="charPool">The <see cref="ArrayPool{Char}"/>.</param>
        /// <param name="objectPoolProvider">The <see cref="ObjectPoolProvider"/>.</param>
        /// <param name="options">The <see cref="MvcOptions"/>.</param>
        /// <param name="jsonOptions">The <see cref="MvcJsonOptions"/>.</param>
        public JsonInputFormatter(
            ILogger logger,
            JsonSerializerSettings serializerSettings,
            ArrayPool <char> charPool,
            ObjectPoolProvider objectPoolProvider,
            MvcOptions options,
            MvcJsonOptions jsonOptions)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

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

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

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

            _logger             = logger;
            SerializerSettings  = serializerSettings;
            _charPool           = new JsonArrayPool <char>(charPool);
            _objectPoolProvider = objectPoolProvider;
            _options            = options;
            _jsonOptions        = jsonOptions;

            SupportedEncodings.Add(UTF8EncodingWithoutBOM);
            SupportedEncodings.Add(UTF16EncodingLittleEndian);

            SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationJson);
            SupportedMediaTypes.Add(MediaTypeHeaderValues.TextJson);
            SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationAnyJsonSyntax);
        }
示例#27
0
        public MessagingRoot(
            ObjectPoolProvider pooling,
            BusSettings settings,
            HandlerGraph handlers,
            Forwarders forwarders,
            IPersistence persistence,
            IChannelGraph channels,
            ISubscriptionsRepository subscriptions,
            IEnumerable <ISerializerFactory> serializers,
            IEnumerable <IMessageDeserializer> readers,
            IEnumerable <IMessageSerializer> writers,
            IMessageLogger[] loggers,
            ITransport[] transports,
            IEnumerable <IMissingHandler> missingHandlers,
            IEnumerable <IUriLookup> lookups)
        {
            _settings    = settings;
            _handlers    = handlers;
            _replies     = new ReplyWatcher();
            _persistence = persistence;
            _channels    = channels;
            _transports  = transports;



            Lookup = new UriAliasLookup(lookups);


            Serialization = new BusMessageSerializationGraph(pooling, settings, handlers, forwarders, serializers,
                                                             readers, writers);

            Logger = new CompositeMessageLogger(loggers);

            Pipeline = new HandlerPipeline(Serialization, handlers, _replies, Logger, missingHandlers,
                                           new Lazy <IServiceBus>(Build));

            Workers = new WorkerQueue(Logger, Pipeline, settings);

            Router = new MessageRouter(Serialization, channels, subscriptions, handlers, Logger, Lookup, settings);

            ScheduledJobs = new InMemoryScheduledJobProcessor();
        }
示例#28
0
        public JsonInputFormatter(
            ILogger logger,
            JsonSerializerSettings serializerSettings,
            ArrayPool <char> charPool,
            ObjectPoolProvider objectPoolProvider,
            bool suppressInputFormatterBuffering,
            bool allowInputFormatterExceptionMessages)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

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

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

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

            _logger             = logger;
            SerializerSettings  = serializerSettings;
            _charPool           = new JsonArrayPool <char>(charPool);
            _objectPoolProvider = objectPoolProvider;
            _suppressInputFormatterBuffering      = suppressInputFormatterBuffering;
            _allowInputFormatterExceptionMessages = allowInputFormatterExceptionMessages;

            SupportedEncodings.Add(UTF8EncodingWithoutBOM);
            SupportedEncodings.Add(UTF16EncodingLittleEndian);

            SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationJson);
            SupportedMediaTypes.Add(MediaTypeHeaderValues.TextJson);
            SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationAnyJsonSyntax);
        }
        private static IInputFormatter[] GetInputFormatters(
            ILoggerFactory loggerFactory,
            ArrayPool <char> charPool,
            ObjectPoolProvider objectPoolProvider,
            IOptions <MvcOptions> mvcOptions,
            IOptions <MvcNewtonsoftJsonOptions> jsonOptions)
        {
            var jsonOptionsValue = jsonOptions.Value;

            return(new IInputFormatter[]
            {
                new NewtonsoftJsonInputFormatter(
                    loggerFactory.CreateLogger <NewtonsoftJsonBodyModelBinder>(),
                    jsonOptionsValue.SerializerSettings,
                    charPool,
                    objectPoolProvider,
                    mvcOptions.Value,
                    jsonOptionsValue)
            });
        }
示例#30
0
        /// <summary>
        /// Initializes a new instance of <see cref="JsonInputFormatter"/>.
        /// </summary>
        /// <param name="logger">The <see cref="ILogger"/>.</param>
        /// <param name="serializerSettings">
        /// The <see cref="JsonSerializerSettings"/>. Should be either the application-wide settings
        /// (<see cref="MvcJsonOptions.SerializerSettings"/>) or an instance
        /// <see cref="JsonSerializerSettingsProvider.CreateSerializerSettings"/> initially returned.
        /// </param>
        /// <param name="charPool">The <see cref="ArrayPool{Char}"/>.</param>
        /// <param name="objectPoolProvider">The <see cref="ObjectPoolProvider"/>.</param>
        public JsonInputFormatter(
            ILogger logger,
            JsonSerializerSettings serializerSettings,
            ArrayPool<char> charPool,
            ObjectPoolProvider objectPoolProvider)
        {
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

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

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

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

            _logger = logger;
            SerializerSettings = serializerSettings;
            _charPool = new JsonArrayPool<char>(charPool);
            _objectPoolProvider = objectPoolProvider;

            SupportedEncodings.Add(UTF8EncodingWithoutBOM);
            SupportedEncodings.Add(UTF16EncodingLittleEndian);

            SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationJson);
            SupportedMediaTypes.Add(MediaTypeHeaderValues.TextJson);
        }
示例#31
0
        public static void ConfigureMvc(
            MvcOptions options,
            JsonSerializerSettings serializerSettings,
            ILoggerFactory loggerFactory,
            ArrayPool <char> charPool,
            ObjectPoolProvider objectPoolProvider,
            MvcJsonOptions jsonOptions = null)
        {
            serializerSettings.Formatting = Formatting.Indented;

            serializerSettings.Converters.Add(new DateTimeOffsetFormatJsonConverter());
            serializerSettings.DateParseHandling = DateParseHandling.None;

            options.OutputFormatters.Clear();

            var jsonOutputFormatter =
#if NETCOREAPP3_0 || NETCOREAPP3_1 || NET5_0
                new NewtonsoftJsonOutputFormatter(serializerSettings, charPool, options);
#elif NETSTANDARD2_0 || NETFRAMEWORK
                new JsonOutputFormatter(serializerSettings, charPool);
#else
#error unknown target framework
#endif

            options.OutputFormatters.Add(jsonOutputFormatter);

            options.InputFormatters.Clear();
            var jsonInputLogger = loggerFactory.CreateLogger <HypermediaApiJsonInputFormatter>();
            options.InputFormatters.Add(new HypermediaApiJsonInputFormatter(
                                            jsonInputLogger,
                                            serializerSettings,
                                            charPool,
                                            objectPoolProvider,
                                            options,
                                            jsonOptions));
        }
示例#32
0
        public MvcJsonMvcOptionsSetup(
            ILoggerFactory loggerFactory,
            ArrayPool <char> charPool,
            ObjectPoolProvider objectPoolProvider)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

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

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

            _loggerFactory      = loggerFactory;
            _charPool           = charPool;
            _objectPoolProvider = objectPoolProvider;
        }
        public static void ConfigureMvc(
            MvcOptions options,
            JsonSerializerSettings serializerSettings,
            ILoggerFactory loggerFactory,
            ArrayPool <char> charPool,
            ObjectPoolProvider objectPoolProvider)
        {
            serializerSettings.Formatting = Formatting.Indented;

            serializerSettings.Converters.Add(new DateTimeOffsetFormatJsonConverter());
            serializerSettings.DateParseHandling = DateParseHandling.None;

            options.OutputFormatters.Clear();
            options.OutputFormatters.Add(new JsonOutputFormatter(serializerSettings, charPool));

            options.InputFormatters.Clear();
            var jsonInputLogger = loggerFactory.CreateLogger <HypermediaApiJsonInputFormatter>();

            options.InputFormatters.Add(new HypermediaApiJsonInputFormatter(
                                            jsonInputLogger,
                                            serializerSettings,
                                            charPool,
                                            objectPoolProvider));
        }
 public HttpContextFactory(ObjectPoolProvider poolProvider, IOptions<FormOptions> formOptions)
     : this(poolProvider, formOptions, httpContextAccessor: null)
 {
 }
 public PooledHttpContextFactory(ObjectPoolProvider poolProvider)
     : this(poolProvider, httpContextAccessor: null)
 {
 }
示例#36
0
 public YourMvcOptionsSetup(ILoggerFactory loggerFactory, IOptions<MvcJsonOptions> jsonOptions, ArrayPool<char> charPool, ObjectPoolProvider objectPoolProvider)
 {
     //Validate parameters and set fields
 }
 public MediaTypeJsonInputFormatter(ILogger logger, JsonSerializerSettings serializerSettings, ArrayPool<char> charPool, ObjectPoolProvider objectPoolProvider)
     : base(logger, serializerSettings, charPool, objectPoolProvider)
 {
 }
    public MyModelBinder(IHttpRequestStreamReaderFactory readerFactory, ILoggerFactory loggerFactory, IOptions <MvcOptions> options, IOptions <MvcJsonOptions> jsonOptions, ArrayPool <char> charPool, ObjectPoolProvider objectPoolProvider)
    {
        var formatters         = options.Value.InputFormatters.ToList();
        int jsonFormatterIndex = formatters.FirstIndexOf(formatter => formatter is JsonInputFormatter);
        JsonSerializerSettings myCustomSettings = ...
                                                  formatters[jsonFormatterIndex] = new JsonInputFormatter(loggerFactory.CreateLogger("MyCustomJsonFormatter"), myCustomSettings, charPool, objectPoolProvider, options.Value, jsonOptions.Value);

        _bodyModelBinder = new BodyModelBinder(formatters, readerFactory, loggerFactory, options.Value);
    }