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

Disambiguate NetheriteFactory constructor and rev version #401

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

davidmrdavid
Copy link
Member

@davidmrdavid davidmrdavid commented Jun 5, 2024

There are two NetheriteProviderFactory constructors:

/// <summary>
/// This constructor should not be called directly. It is here only to avoid breaking changes.
/// </summary>
[Obsolete]
public NetheriteProviderFactory(
IOptions<DurableTaskOptions> extensionOptions,
ILoggerFactory loggerFactory,
#pragma warning disable CS0618 // Type or member is obsolete
IConnectionStringResolver connectionStringResolver,
#pragma warning restore CS0618 // Type or member is obsolete
IHostIdProvider hostIdProvider,
INameResolver nameResolver,
#pragma warning disable CS0612 // Type or member is obsolete
IPlatformInformation platformInfo)
#pragma warning restore CS0612 // Type or member is obsolete
: this(extensionOptions, loggerFactory, hostIdProvider, nameResolver, serviceProvider:null, ConnectionResolver.FromConnectionNameToConnectionStringResolver((s) => nameResolver.Resolve(s)), platformInfo)
{
}
/// <summary>
/// This constructor should not be called directly. The DI logic calls this when it constructs all the
/// durability provider factories for use by <see cref="Microsoft.Azure.WebJobs.Extensions.DurableTask.DurableTaskExtension"/>.
/// </summary>
[ActivatorUtilitiesConstructor]
public NetheriteProviderFactory(
IOptions<DurableTaskOptions> extensionOptions,
ILoggerFactory loggerFactory,
IHostIdProvider hostIdProvider,
INameResolver nameResolver,
IServiceProvider serviceProvider,
DurableTask.Netherite.ConnectionResolver connectionResolver,
#pragma warning disable CS0612 // Type or member is obsolete
IPlatformInformation platformInfo)
#pragma warning restore CS0612 // Type or member is obsolete
{
this.options = extensionOptions?.Value ?? throw new ArgumentNullException(nameof(extensionOptions));
this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
this.nameResolver = nameResolver ?? throw new ArgumentNullException(nameof(nameResolver));
this.serviceProvider = serviceProvider;
this.hostIdProvider = hostIdProvider;
this.connectionResolver = connectionResolver;
this.inConsumption = platformInfo.IsInConsumptionPlan();
bool ReadBooleanSetting(string name) => this.options.StorageProvider.TryGetValue(name, out object objValue)
&& objValue is string stringValue && bool.TryParse(stringValue, out bool boolValue) && boolValue;
this.TraceToConsole = ReadBooleanSetting(nameof(this.TraceToConsole));
this.TraceToBlob = ReadBooleanSetting(nameof(this.TraceToBlob));
WorkerRuntimeType runtimeType = platformInfo.GetWorkerRuntimeType();
if (runtimeType == WorkerRuntimeType.DotNetIsolated ||
runtimeType == WorkerRuntimeType.Java ||
runtimeType == WorkerRuntimeType.Custom)
{
this.usesNewPassthroughMiddlewareForEntities = true;
}
}
. One is obsolete, and the other is not.

We used the ActivatorUtilitiesConstructor to tell DI which constructor to choose. However, it seems that annotation isn't honored in .NET8: dotnet/runtime#95915.

Due to some combination of this .NET8 change, and the Host for Flex Consumption using a new DI library, DF apps in Flex Consumption using bundles are now failing with the following exception:

System.InvalidOperationException : Unable to activate type 'DurableTask.Netherite.AzureFunctions.NetheriteProviderFactory'. The following constructors are ambiguous:
Void .ctor(Microsoft.Extensions.Options.IOptions1[Microsoft.Azure.WebJobs.Extensions.DurableTask.DurableTaskOptions], Microsoft.Extensions.Logging.ILoggerFactory, Microsoft.Azure.WebJobs.Host.Executors.IHostIdProvider, Microsoft.Azure.WebJobs.INameResolver, System.IServiceProvider, DurableTask.Netherite.ConnectionResolver, Microsoft.Azure.WebJobs.Extensions.DurableTask.IPlatformInformation) Void .ctor(Microsoft.Extensions.Options.IOptions1[Microsoft.Azure.WebJobs.Extensions.DurableTask.DurableTaskOptions], Microsoft.Extensions.Logging.ILoggerFactory, Microsoft.Azure.WebJobs.Extensions.DurableTask.IConnectionStringResolver, Microsoft.Azure.WebJobs.Host.Executors.IHostIdProvider, Microsoft.Azure.WebJobs.INameResolver, Microsoft.Azure.WebJobs.Extensions.DurableTask.IPlatformInformation)

This PR disambiguates the constructors by creating a new internal wrapper class, UnambiguousNetheriteProviderFactory, that re-exposes only the expected constructor, and registering it as the service provider for IDurabilityProviderFactory. This is a workaround suggested by Fabio from the Host team.

@davidmrdavid davidmrdavid merged commit 928f933 into main Jun 5, 2024
2 checks passed
@davidmrdavid davidmrdavid deleted the dajusto/disambiguate-constructor branch June 5, 2024 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants