Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewtonsoftServiceCollectionExtensions improvements to allow pass custom JsonSerializerSettings #2398

Closed
JBaltika opened this issue Apr 12, 2022 · 2 comments

Comments

@JBaltika
Copy link

Hi,
I think it should be one more extension method that allows passing custom JsonSerializerSettings as well. In my case, I just copy/paste the class and refactored it, but its better for not to have hacked code in the projects

namespace Microsoft.Extensions.DependencyInjection
{
    public static class NewtonsoftServiceCollectionExtensions
    {
        public static IServiceCollection AddSwaggerGenNewtonsoftSupport(this IServiceCollection services)
        {
            return services.Replace(
                ServiceDescriptor.Transient<ISerializerDataContractResolver>((s) =>
                {
                    var serializerSettings = s.GetRequiredService<IOptions<MvcNewtonsoftJsonOptions>>().Value?.SerializerSettings
                        ?? **new JsonSerializerSettings()**;
                    return new NewtonsoftDataContractResolver(serializerSettings);
                }));
        }
    }
}

https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/fcbec2c701a7e0533c3ec6f1bbc5232780bade0f/src/Swashbuckle.AspNetCore.Newtonsoft/DependencyInjection/NewtonsoftServiceCollectionExtensions.cs

Copy link
Contributor

This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.

@github-actions github-actions bot added the stale Stale issues or pull requests label Apr 25, 2024
@martincostello martincostello removed the stale Stale issues or pull requests label Apr 25, 2024
@martincostello
Copy link
Collaborator

As noted in #2799, this adds too much complexity. Providing custom implementations in the service container is the way to provide exacting behaviour for your needs.

Also, as we support two serializers, this doubles the amount of work needed if we did do this.

@martincostello martincostello closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants