Skip to content

Commit

Permalink
App builder extension method to register extension options (#1843)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Jacob Viau <[email protected]>
  • Loading branch information
liliankasem and jviau authored Aug 29, 2023
1 parent c1ee4a0 commit 170945f
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 42 deletions.
5 changes: 3 additions & 2 deletions extensions/Worker.Extensions.CosmosDB/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- My change description (#PR/#issue)
-->

### Microsoft.Azure.Functions.Worker.Extensions.CosmosDB <version>
### Microsoft.Azure.Functions.Worker.Extensions.CosmosDB 4.4.2

- <entry>
- Implement IFunctionsWorkerApplicationBuilder.ConfigureCosmosDB() extension method
- F# projects need to configure the extension manually due to source gen restrictions
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ internal class CosmosDBBindingOptionsSetup : IConfigureNamedOptions<CosmosDBBind
{
private readonly IConfiguration _configuration;
private readonly AzureComponentFactory _componentFactory;
private readonly IOptionsMonitor<WorkerOptions> _workerOptions;

public CosmosDBBindingOptionsSetup(IConfiguration configuration, AzureComponentFactory componentFactory)
public CosmosDBBindingOptionsSetup(IConfiguration configuration, AzureComponentFactory componentFactory, IOptionsMonitor<WorkerOptions> workerOptions)
{
_configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
_componentFactory = componentFactory ?? throw new ArgumentNullException(nameof(componentFactory));
_workerOptions = workerOptions ?? throw new ArgumentNullException(nameof(workerOptions));
}

public void Configure(CosmosDBBindingOptions options)
Expand Down Expand Up @@ -53,6 +55,8 @@ public void Configure(string connectionName, CosmosDBBindingOptions options)

options.Credential = _componentFactory.CreateTokenCredential(connectionSection);
}

options.Serializer = new WorkerCosmosSerializer(_workerOptions.CurrentValue.Serializer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
// Licensed under the MIT License. See License.txt in the project root for license information.

using System;
using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Core;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

[assembly: WorkerExtensionStartup(typeof(CosmosExtensionStartup))]

Expand All @@ -22,16 +18,7 @@ public override void Configure(IFunctionsWorkerApplicationBuilder applicationBui
throw new ArgumentNullException(nameof(applicationBuilder));
}

applicationBuilder.Services.AddAzureClientsCore(); // Adds AzureComponentFactory

applicationBuilder.Services.AddOptions<CosmosDBBindingOptions>()
.Configure<IOptions<WorkerOptions>>((cosmosOptions, workerOptions) =>
{
CosmosSerializer cosmosSerializer = new WorkerCosmosSerializer(workerOptions?.Value?.Serializer);
cosmosOptions.Serializer = cosmosSerializer;
});

applicationBuilder.Services.AddSingleton<IConfigureOptions<CosmosDBBindingOptions>, CosmosDBBindingOptionsSetup>();
applicationBuilder.ConfigureCosmosDBExtension();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Extensions.Azure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;

namespace Microsoft.Azure.Functions.Worker
{
/// <summary>
/// Provides extension methods to work with a <see cref="IFunctionsWorkerApplicationBuilder"/>.
/// </summary>
public static class FunctionsWorkerApplicationBuilderExtensions
{
/// <summary>
/// Configures the CosmosDB extension.
/// </summary>
/// <param name="builder">The <see cref="IFunctionsWorkerApplicationBuilder"/> to configure.</param>
/// <returns>The same instance of the <see cref="IFunctionsWorkerApplicationBuilder"/> for chaining.</returns>
public static IFunctionsWorkerApplicationBuilder ConfigureCosmosDBExtension(this IFunctionsWorkerApplicationBuilder builder)
{
if (builder is null)
{
throw new System.ArgumentNullException(nameof(builder));
}

builder.Services.AddAzureClientsCore(); // Adds AzureComponentFactory
builder.Services.AddOptions<CosmosDBBindingOptions>();
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IConfigureOptions<CosmosDBBindingOptions>, CosmosDBBindingOptionsSetup>());

return builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Description>Azure Cosmos DB extensions for .NET isolated functions</Description>

<!--Version information-->
<VersionPrefix>4.4.1</VersionPrefix>
<VersionPrefix>4.4.2</VersionPrefix>

<!--Temporarily opting out of documentation. Pending documentation-->
<GenerateDocumentationFile>false</GenerateDocumentationFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
using System;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Core;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

[assembly: WorkerExtensionStartup(typeof(StorageExtensionStartup))]
[assembly: WorkerExtensionStartup(typeof(BlobStorageExtensionStartup))]

namespace Microsoft.Azure.Functions.Worker
{
public class StorageExtensionStartup : WorkerExtensionStartup
public class BlobStorageExtensionStartup : WorkerExtensionStartup
{
public override void Configure(IFunctionsWorkerApplicationBuilder applicationBuilder)
{
Expand All @@ -21,9 +18,7 @@ public override void Configure(IFunctionsWorkerApplicationBuilder applicationBui
throw new ArgumentNullException(nameof(applicationBuilder));
}

applicationBuilder.Services.AddAzureClientsCore(); // Adds AzureComponentFactory
applicationBuilder.Services.AddOptions<BlobStorageBindingOptions>();
applicationBuilder.Services.AddSingleton<IConfigureOptions<BlobStorageBindingOptions>, BlobStorageBindingOptionsSetup>();
applicationBuilder.ConfigureBlobStorageExtension();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Extensions.Azure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;

namespace Microsoft.Azure.Functions.Worker
{
/// <summary>
/// Provides extension methods to work with a <see cref="IFunctionsWorkerApplicationBuilder"/>.
/// </summary>
public static class FunctionsWorkerApplicationBuilderExtensions
{
/// <summary>
/// Configures the CosmosDB extension.
/// </summary>
/// <param name="builder">The <see cref="IFunctionsWorkerApplicationBuilder"/> to configure.</param>
/// <returns>The same instance of the <see cref="IFunctionsWorkerApplicationBuilder"/> for chaining.</returns>
public static IFunctionsWorkerApplicationBuilder ConfigureBlobStorageExtension(this IFunctionsWorkerApplicationBuilder builder)
{
if (builder is null)
{
throw new System.ArgumentNullException(nameof(builder));
}

builder.Services.AddAzureClientsCore(); // Adds AzureComponentFactory
builder.Services.AddOptions<BlobStorageBindingOptions>();
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IConfigureOptions<BlobStorageBindingOptions>, BlobStorageBindingOptionsSetup>());

return builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Description>Azure Blob Storage extensions for .NET isolated functions</Description>

<!--Version information-->
<VersionPrefix>6.1.0</VersionPrefix>
<VersionPrefix>6.1.1</VersionPrefix>

<!--Temporarily opting out of documentation. Pending documentation-->
<GenerateDocumentationFile>false</GenerateDocumentationFile>
Expand Down
9 changes: 5 additions & 4 deletions extensions/Worker.Extensions.Storage/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
- My change description (#PR/#issue)
-->

### Microsoft.Azure.Functions.Worker.Extensions.Storage 6.1.0
### Microsoft.Azure.Functions.Worker.Extensions.Storage 6.1.1

- Updated `Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs` to 6.1.0
- Updated `Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs` to 6.1.1

### Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs 6.1.0
### Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs 6.1.1

- Added support for trigger sources, enabling use of Event Grid for change detection/notification
- Implement IFunctionsWorkerApplicationBuilder.ConfigureBlobStorage() extension method
- F# projects need to configure the extension manually due to source gen restrictions
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Description>Azure Storage extensions for .NET isolated functions</Description>

<!--Version information-->
<VersionPrefix>6.1.0</VersionPrefix>
<VersionPrefix>6.1.1</VersionPrefix>

<!--Temporarily opting out of documentation. Pending documentation-->
<GenerateDocumentationFile>false</GenerateDocumentationFile>
Expand Down
5 changes: 3 additions & 2 deletions extensions/Worker.Extensions.Tables/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- My change description (#PR/#issue)
-->

### Microsoft.Azure.Functions.Worker.Extensions.Tables <version>
### Microsoft.Azure.Functions.Worker.Extensions.Tables 1.2.1

- <entry>
- Implement IFunctionsWorkerApplicationBuilder.ConfigureTables() extension method
- F# projects need to configure the extension manually due to source gen restrictions
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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.Functions.Worker.Extensions.Tables.Config;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;

namespace Microsoft.Azure.Functions.Worker
{
/// <summary>
/// Provides extension methods to work with a <see cref="IFunctionsWorkerApplicationBuilder"/>.
/// </summary>
public static class FunctionsWorkerApplicationBuilderExtensions
{
/// <summary>
/// Configures the CosmosDB extension.
/// </summary>
/// <param name="builder">The <see cref="IFunctionsWorkerApplicationBuilder"/> to configure.</param>
/// <returns>The same instance of the <see cref="IFunctionsWorkerApplicationBuilder"/> for chaining.</returns>
public static IFunctionsWorkerApplicationBuilder ConfigureTablesExtension(this IFunctionsWorkerApplicationBuilder builder)
{
if (builder is null)
{
throw new System.ArgumentNullException(nameof(builder));
}

builder.Services.AddAzureClientsCore(); // Adds AzureComponentFactory
builder.Services.AddOptions<TablesBindingOptions>();
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IConfigureOptions<TablesBindingOptions>, TablesBindingOptionsSetup>());

return builder;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
using System;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Core;
using Microsoft.Azure.Functions.Worker.Extensions.Tables.Config;
using Microsoft.Extensions.Azure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

[assembly: WorkerExtensionStartup(typeof(TableExtensionStartup))]

Expand All @@ -28,9 +24,7 @@ public override void Configure(IFunctionsWorkerApplicationBuilder applicationBui
throw new ArgumentNullException(nameof(applicationBuilder));
}

applicationBuilder.Services.AddAzureClientsCore(); // Adds AzureComponentFactory
applicationBuilder.Services.AddOptions<TablesBindingOptions>();
applicationBuilder.Services.AddSingleton<IConfigureOptions<TablesBindingOptions>, TablesBindingOptionsSetup>();
applicationBuilder.ConfigureTablesExtension();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Description>Azure Table Storage extensions for .NET isolated functions</Description>

<!--Version information-->
<VersionPrefix>1.2.0</VersionPrefix>
<VersionPrefix>1.2.1</VersionPrefix>

</PropertyGroup>

Expand Down

0 comments on commit 170945f

Please sign in to comment.