nclient / NClient

:dizzy: NClient is an automatic type-safe .Net HTTP client that allows you to call web service API methods using annotated interfaces or controllers without boilerplate code.
Apache License 2.0
43 stars 11 forks source link

Think about custom generate serializator #407

Closed Kingmidas74 closed 2 years ago

Kingmidas74 commented 2 years ago

According to this list of advice (see No. 5), using your custom serializators it better than generic stuff. Also, System.Text.Json can generate serializators based on DTO. See this.

What if we can implements compile-time generation of serializers based on generic T parameter in default provider?

Maybe it could improve performance of NClient.

smolchanovsky commented 2 years ago

It seems to be enough to add context to the serializer options, and then pass them to the client:

var options = new JsonSerializerOptions();
options.AddContext<MyJsonSerializerContext>();

services.AddNClient<IFileClient>(host: "http://localhost:5001", builder =>
    builder.WithSystemTextJsonSerialization(options).Build());

By the way, after closing https://github.com/nclient/NClient/issues/410 issue, it will become even easier to do this.

smolchanovsky commented 2 years ago

@Kingmidas74, I suggest you write tests to make sure it works :)