コード例 #1
0
        /// <summary>
        /// Configures Newtonsoft.Json specific features such as input and output formatters.
        /// </summary>
        /// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
        /// <returns>The <see cref="IMvcBuilder"/>.</returns>
        public static IMvcBuilder AddNewtonsoftJson(this IMvcBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            NewtonsoftJsonMvcCoreBuilderExtensions.AddServicesCore(builder.Services);
            return(builder);
        }
コード例 #2
0
        public void AddServicesCore_ReplacesDefaultTempDataSerializer()
        {
            // Arrange
            var services = new ServiceCollection()
                           .AddSingleton <TempDataSerializer, DefaultTempDataSerializer>();

            // Act
            NewtonsoftJsonMvcCoreBuilderExtensions.AddServicesCore(services);

            // Assert
            var tempDataSerializer = Assert.Single(services, d => d.ServiceType == typeof(TempDataSerializer));

            Assert.Same(typeof(BsonTempDataSerializer), tempDataSerializer.ImplementationType);
        }
コード例 #3
0
        public void AddServicesCore_ReplacesDefaultJsonResultExecutor()
        {
            // Arrange
            var services = new ServiceCollection()
                           .AddSingleton <IActionResultExecutor <JsonResult>, SystemTextJsonResultExecutor>();

            // Act
            NewtonsoftJsonMvcCoreBuilderExtensions.AddServicesCore(services);

            // Assert
            var jsonResultExecutor = Assert.Single(services, d => d.ServiceType == typeof(IActionResultExecutor <JsonResult>));

            Assert.Same(typeof(NewtonsoftJsonResultExecutor), jsonResultExecutor.ImplementationType);
        }
コード例 #4
0
        /// <summary>
        /// Configures Newtonsoft.Json specific features such as input and output formatters.
        /// </summary>
        /// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
        /// <param name="setupAction">Callback to configure <see cref="MvcNewtonsoftJsonOptions"/>.</param>
        /// <returns>The <see cref="IMvcBuilder"/>.</returns>
        public static IMvcBuilder AddNewtonsoftJson(
            this IMvcBuilder builder,
            Action <MvcNewtonsoftJsonOptions> setupAction)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            NewtonsoftJsonMvcCoreBuilderExtensions.AddServicesCore(builder.Services);
            builder.Services.Configure(setupAction);

            return(builder);
        }