nats.net icon indicating copy to clipboard operation
nats.net copied to clipboard

Accept multiple JSON serialization contexts in DI

Open mtmk opened this issue 1 year ago • 3 comments

Proposed change

public NatsBuilder AddJsonSerialization(params JsonSerializerContext[] contexts)
    => ConfigureOptions(opts =>
    {
        var jsonRegistry = new NatsJsonContextSerializerRegistry(contexts);
        return opts with { SerializerRegistry = jsonRegistry };
    });

...or collect them to add them in the end during build:

public NatsBuilder AddJsonSerialization(params JsonSerializerContext[] contexts)
    => _contexts.AddRange(contexts);

cc @rickdotnet

mtmk avatar May 30 '24 17:05 mtmk

I rushed this original implementation and missed that NatsJsonContextSerializerRegistry took in params.

If I pick this up, I'll probably opt for the first option unless someone has opinions against it.

rickdotnet avatar Jun 25 '24 15:06 rickdotnet

@mtmk , should we wait to see where https://github.com/nats-io/nats.net.v2/pull/530 goes? Or do you think it's worth getting this in sooner?

rickdotnet avatar Jul 06 '24 12:07 rickdotnet

@mtmk , should we wait to see where #530 goes? Or do you think it's worth getting this in sooner?

@rickdotnet yes good idea. There might be multiple issues and PRs. I might also create a project or milestone for these as well once we have consensus.

mtmk avatar Jul 06 '24 14:07 mtmk

since we'll be deprecating this with #689 I shall close this

mtmk avatar Jan 26 '25 02:01 mtmk

Fine by me.

rickdotnet avatar Feb 03 '25 22:02 rickdotnet