Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App builder extension method to register extension options #1843

Merged
merged 8 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.ConfigureCosmosDB();
}
}
}
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 ConfigureCosmosDB(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.ConfigureBlobStorage();
}
}
}
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 ConfigureBlobStorage(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.01

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

### 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 ConfigureTables(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.ConfigureTables();
}
}
}
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
Loading