-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
CosmosDBOptions
to allow configuration of the CosmosDB s…
…ervice client via `CosmosClientOptions` (#2483)
- Loading branch information
1 parent
9994356
commit ab70ee0
Showing
7 changed files
with
113 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
extensions/Worker.Extensions.CosmosDB/src/Config/CosmosDBExtensionOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using Microsoft.Azure.Cosmos; | ||
|
||
namespace Microsoft.Azure.Functions.Worker | ||
{ | ||
public class CosmosDBExtensionOptions | ||
{ | ||
/// <summary> | ||
/// Gets or sets the CosmosClientOptions. | ||
/// </summary> | ||
public CosmosClientOptions ClientOptions { get; set; } = new() { ConnectionMode = ConnectionMode.Gateway }; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
extensions/Worker.Extensions.CosmosDB/src/Extensions/CloningExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Reflection; | ||
using Microsoft.Azure.Cosmos; | ||
|
||
namespace Microsoft.Azure.Functions.Worker | ||
{ | ||
internal static class CloningExtensions | ||
{ | ||
public static T MemberwiseClone<T>(this T original) | ||
{ | ||
if (original is null) | ||
{ | ||
throw new ArgumentNullException(nameof(original)); | ||
} | ||
|
||
// Get the type of the object | ||
Type type = original.GetType(); | ||
|
||
// Get the internal Clone method | ||
MethodInfo cloneMethod = type.GetMethod("MemberwiseClone", BindingFlags.Instance | BindingFlags.NonPublic); | ||
|
||
if (cloneMethod is null) | ||
{ | ||
throw new InvalidOperationException("The MemberwiseClone method could not be found."); | ||
} | ||
|
||
// Invoke the Clone method | ||
return (T)cloneMethod.Invoke(original, null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters