我可以将 Newtonsoft.Json 与 CosmosDb v3 一起使用吗?

phi*_*hil 5 c# .net-core azure-cosmosdb

我已按照这些说明与 CosmosDb v3Newtonsoft一起在我的 Blazor Server 项目中使用。

因此我Startup.cs指定了几个设置和转换器。

  services.AddControllers()
    .AddNewtonsoftJson(options =>
    {
        options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
        options.SerializerSettings.Formatting = Formatting.Indented;
        options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
        options.SerializerSettings.DefaultValueHandling = DefaultValueHandling.Ignore;
        options.SerializerSettings.Converters.Add(new ISubfileConverter());
        options.SerializerSettings.Converters.Add(new ISubunitConverter());
        options.SerializerSettings.Converters.Add(new IElementConverter());
        options.SerializerSettings.Converters.Add(new IMetadataConverter());
    });

    services.AddSingleton<ICosmosSrcDocService>(InitializeCosmosSrcClientInstance(Configuration.GetSection("SourceCosmosDb"))
                .GetAwaiter().GetResult());


Run Code Online (Sandbox Code Playgroud)

然而,当我使用UpsertItemAsync()它时,它似乎没有使用它。

有没有办法告诉 CosmosDbStartup.cs 使用此配置?

使用 Cosmos 配置更新

   CosmosClientBuilder clientBuilder = new CosmosClientBuilder(account, key);
   CosmosClient client = clientBuilder
      .WithConnectionModeDirect()
      .Build();
      CosmosTrgDocService cosmosDbService = new CosmosTrgDocService(client, databaseName, containerName);

Run Code Online (Sandbox Code Playgroud)