WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit cc17626

Browse files
committed
Use Worker ObjectSerializer by default for Cosmos
1 parent 81b678b commit cc17626

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

extensions/Worker.Extensions.CosmosDB/src/Config/CosmosDBExtensionOptions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ public class CosmosDBExtensionOptions
1313
/// </summary>
1414
public CosmosClientOptions ClientOptions { get; set; } = new() { ConnectionMode = ConnectionMode.Gateway };
1515

16-
// TODO: in next major version, ensure this is WorkerOptions.Serializer by default.
16+
/// <summary>
17+
/// Gets or sets the <see cref="ObjectSerializer" /> to use for Cosmos DB operations.
18+
/// Defaults to the worker serializer if left unset.
19+
/// </summary>
1720
public ObjectSerializer? Serializer { get; set; }
1821
}
1922
}

extensions/Worker.Extensions.CosmosDB/src/Extensions/FunctionsWorkerApplicationBuilderExtensions.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public static IFunctionsWorkerApplicationBuilder ConfigureCosmosDBExtension(
3333
builder.Services.AddOptions<CosmosDBExtensionOptions>()
3434
.PostConfigure<IOptions<WorkerOptions>>((cosmos, worker) =>
3535
{
36-
ObjectSerializer? serializer = cosmos.Serializer ?? worker.Value.Serializer;
36+
cosmos.Serializer ??= worker.Value.Serializer;
37+
ObjectSerializer? serializer = cosmos.Serializer;
3738
if (serializer is not null && cosmos.ClientOptions.Serializer is null)
3839
{
3940
cosmos.ClientOptions.Serializer = new WorkerCosmosSerializer(serializer);
@@ -58,21 +59,5 @@ public static IFunctionsWorkerApplicationBuilder ConfigureCosmosDBExtensionOptio
5859
builder.Services.Configure(options);
5960
return builder;
6061
}
61-
62-
/// <summary>
63-
/// Configures the CosmosDBExtensionOptions for the Functions Worker Cosmos extension.
64-
/// </summary>
65-
/// <param name="builder">The IFunctionsWorkerApplicationBuilder to add the configuration to.</param>
66-
/// <returns>The same instance of the <see cref="IFunctionsWorkerApplicationBuilder"/> for chaining.</returns>
67-
public static IFunctionsWorkerApplicationBuilder UseCosmosDBWorkerSerializer(this IFunctionsWorkerApplicationBuilder builder)
68-
{
69-
builder.Services.AddOptions<CosmosDBExtensionOptions>()
70-
.Configure<IOptions<WorkerOptions>>((cosmos, worker) =>
71-
{
72-
cosmos.Serializer ??= worker.Value.Serializer;
73-
});
74-
75-
return builder;
76-
}
7762
}
7863
}

0 commit comments

Comments
 (0)