diff --git a/src/Swashbuckle.AspNetCore.Filters/Examples/MvcOutputFormatter.cs b/src/Swashbuckle.AspNetCore.Filters/Examples/MvcOutputFormatter.cs index 7d0cc77..69d041d 100755 --- a/src/Swashbuckle.AspNetCore.Filters/Examples/MvcOutputFormatter.cs +++ b/src/Swashbuckle.AspNetCore.Filters/Examples/MvcOutputFormatter.cs @@ -48,13 +48,6 @@ private OutputFormatterSelector OutputFormatterSelector } } - public MvcOutputFormatter(IOptions options, ILoggerFactory loggerFactory) - : this(options, - GetDefaultServiceProvider(), - loggerFactory) - { - } - public MvcOutputFormatter(IOptions options, IServiceProvider serviceProvider, ILoggerFactory loggerFactory) { this.initializedOutputFormatterSelector = false; @@ -169,11 +162,6 @@ private static HttpContext GetHttpContext( return httpContext; } - private static IServiceProvider GetDefaultServiceProvider() - => new ServiceCollection() - .AddSingleton(Options.Create(new MvcOptions())) - .BuildServiceProvider(); - internal class FormatterNotFoundException : Exception { public FormatterNotFoundException(MediaTypeHeaderValue contentType) diff --git a/test/Swashbuckle.AspNetCore.Filters.Test/Examples/ExamplesOperationFilterTests.cs b/test/Swashbuckle.AspNetCore.Filters.Test/Examples/ExamplesOperationFilterTests.cs index 9c1e997..7af1ce2 100644 --- a/test/Swashbuckle.AspNetCore.Filters.Test/Examples/ExamplesOperationFilterTests.cs +++ b/test/Swashbuckle.AspNetCore.Filters.Test/Examples/ExamplesOperationFilterTests.cs @@ -35,7 +35,7 @@ public ExamplesOperationFilterTests() serviceProvider.GetService(typeof(DictionaryRequestExample)).Returns(new DictionaryRequestExample()); serviceProvider.GetService(typeof(PeopleResponseExample)).Returns(new PeopleResponseExample()); - var mvcOutputFormatter = new MvcOutputFormatter(FormatterOptions.WithXmlAndNewtonsoftJsonAndCsvFormatters, new FakeLoggerFactory()); + var mvcOutputFormatter = new MvcOutputFormatter(FormatterOptions.WithXmlAndNewtonsoftJsonAndCsvFormatters, serviceProvider, new FakeLoggerFactory()); var requestExample = new RequestExample(mvcOutputFormatter, Options.Create(swaggerOptions)); var responseExample = new ResponseExample(mvcOutputFormatter); diff --git a/test/Swashbuckle.AspNetCore.Filters.Test/Examples/MvcFormatterTests.cs b/test/Swashbuckle.AspNetCore.Filters.Test/Examples/MvcFormatterTests.cs index c4db725..02b529f 100644 --- a/test/Swashbuckle.AspNetCore.Filters.Test/Examples/MvcFormatterTests.cs +++ b/test/Swashbuckle.AspNetCore.Filters.Test/Examples/MvcFormatterTests.cs @@ -1,16 +1,14 @@ -using System; -using System.Xml.Linq; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using Microsoft.Net.Http.Headers; +using NSubstitute; using Shouldly; -using Xunit; using Swashbuckle.AspNetCore.Filters.Test.TestFixtures.Fakes; using Swashbuckle.AspNetCore.Filters.Test.TestFixtures.Fakes.Examples; -using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Options; -using NSubstitute; -using Castle.Core.Logging; +using System; +using System.Xml.Linq; +using Xunit; namespace Swashbuckle.AspNetCore.Filters.Test.Examples { @@ -19,7 +17,7 @@ public class GivenAMvcFormatterWithNoOutputFormatters_WhenSerializingAnObject private readonly MvcOutputFormatter sut; public GivenAMvcFormatterWithNoOutputFormatters_WhenSerializingAnObject() - => sut = new MvcOutputFormatter(FormatterOptions.WithoutFormatters, null); + => sut = new MvcOutputFormatter(FormatterOptions.WithoutFormatters, null, null); [Fact] public void ThenAFormatNotFoundExceptionIsThrown() @@ -50,7 +48,7 @@ public class GivenAMvcFormatterWithOutputFormattersButNoLoggerFactory_WhenSerial public GivenAMvcFormatterWithOutputFormattersButNoLoggerFactory_WhenSerializingAnObject() { - sut = new MvcOutputFormatter(FormatterOptions.WithXmlDataContractFormatter, null); + sut = new MvcOutputFormatter(FormatterOptions.WithXmlDataContractFormatter, null, null); } [Fact] @@ -70,7 +68,7 @@ public class GivenAMvcFormatterWithOutputFormatters_WhenSerializingAnObjectForAC private readonly MvcOutputFormatter sut; public GivenAMvcFormatterWithOutputFormatters_WhenSerializingAnObjectForAContentTypeThatIsNotConfigured() - => sut = new MvcOutputFormatter(FormatterOptions.WithXmlDataContractFormatter, new FakeLoggerFactory()); + => sut = new MvcOutputFormatter(FormatterOptions.WithXmlDataContractFormatter, null, new FakeLoggerFactory()); [Fact] public void ThenAFormatNotFoundExceptionIsThrown() @@ -89,7 +87,7 @@ public class GivenAMvcFormatterWitXmlOutputFormatter_WhenSerializingAnObjectAsXm private readonly MvcOutputFormatter sut; public GivenAMvcFormatterWitXmlOutputFormatter_WhenSerializingAnObjectAsXml() - => sut = new MvcOutputFormatter(FormatterOptions.WithXmlDataContractFormatter, new FakeLoggerFactory()); + => sut = new MvcOutputFormatter(FormatterOptions.WithXmlDataContractFormatter, null, new FakeLoggerFactory()); [Fact] public void ThenAnXmlStringIsReturned() diff --git a/test/Swashbuckle.AspNetCore.Filters.Test/Examples/ServiceProviderExamplesOperationFilterTests.cs b/test/Swashbuckle.AspNetCore.Filters.Test/Examples/ServiceProviderExamplesOperationFilterTests.cs index 454df6d..3af8ae6 100644 --- a/test/Swashbuckle.AspNetCore.Filters.Test/Examples/ServiceProviderExamplesOperationFilterTests.cs +++ b/test/Swashbuckle.AspNetCore.Filters.Test/Examples/ServiceProviderExamplesOperationFilterTests.cs @@ -30,7 +30,7 @@ public ServiceProviderExamplesOperationFilterTests() { schemaGeneratorOptions = new SchemaGeneratorOptions(); - var mvcOutputFormatter = new MvcOutputFormatter(FormatterOptions.WithXmlAndNewtonsoftJsonAndCsvFormatters, new FakeLoggerFactory()); + var mvcOutputFormatter = new MvcOutputFormatter(FormatterOptions.WithXmlAndNewtonsoftJsonAndCsvFormatters, serviceProvider, new FakeLoggerFactory()); var requestExample = new RequestExample(mvcOutputFormatter, Options.Create(swaggerOptions)); var responseExample = new ResponseExample(mvcOutputFormatter); @@ -483,7 +483,7 @@ public void SetsResponseExamples_CorrectlyFormatsCsvExample() public void ShouldEmitSystemTextJsonPropertyName() { // Arrange - var mvcOutputFormatter = new MvcOutputFormatter(FormatterOptions.WithSystemTextJsonFormatter, new FakeLoggerFactory()); + var mvcOutputFormatter = new MvcOutputFormatter(FormatterOptions.WithSystemTextJsonFormatter, serviceProvider, new FakeLoggerFactory()); var responseExample = new ResponseExample(mvcOutputFormatter); var sut = new ServiceProviderExamplesOperationFilter(serviceProvider, null, responseExample); diff --git a/test/Swashbuckle.AspNetCore.Filters.Test/Examples/ServiceProviderExamplesOperationFilterWithXmlDataContractTests.cs b/test/Swashbuckle.AspNetCore.Filters.Test/Examples/ServiceProviderExamplesOperationFilterWithXmlDataContractTests.cs index 621a8cf..18e9e5f 100644 --- a/test/Swashbuckle.AspNetCore.Filters.Test/Examples/ServiceProviderExamplesOperationFilterWithXmlDataContractTests.cs +++ b/test/Swashbuckle.AspNetCore.Filters.Test/Examples/ServiceProviderExamplesOperationFilterWithXmlDataContractTests.cs @@ -24,7 +24,7 @@ public ServiceProviderExamplesOperationFilterWithXmlDataContractTests() serviceProvider = Substitute.For(); serviceProvider.GetService(typeof(IExamplesProvider)).Returns(new PersonResponseAutoExample()); - var mvcOutputFormatter = new MvcOutputFormatter(FormatterOptions.WithXmlDataContractFormatter, new FakeLoggerFactory()); + var mvcOutputFormatter = new MvcOutputFormatter(FormatterOptions.WithXmlDataContractFormatter, serviceProvider, new FakeLoggerFactory()); sut = new ServiceProviderExamplesOperationFilter( serviceProvider,