Skip to content

Commit

Permalink
disambiguate Netherite constructor (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmrdavid authored Jun 5, 2024
1 parent 6ee62e3 commit 928f933
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,33 @@ namespace DurableTask.Netherite.AzureFunctions
using Microsoft.Extensions.Options;
using Newtonsoft.Json;

/// <summary>
/// Utility class to disambiguate the right constructor to use for the NetheriteProviderFactory when using DI.
/// We need this class because there's two constructors of NetheriteProviderFactory, one of which is obsolete.
/// Starting in .NET8, this situation can lead to an ambiguous constructor resolution error even when the ActivatorUtilitiesConstructor attribute is used.
/// Therefore, this internal class help us narrow down the constructor selection.
/// </summary>
class UnambiguousNetheriteProviderFactory : NetheriteProviderFactory
{
/// <summary>
/// Constructors a NetheriteProviderFactory using the non-obsolete constructor from the parent class.
/// </summary>
[ActivatorUtilitiesConstructor]
internal UnambiguousNetheriteProviderFactory(
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) : base(extensionOptions, loggerFactory, hostIdProvider, nameResolver, serviceProvider, connectionResolver, platformInfo)
{
}
#pragma warning restore CS0612 // Type or member is obsolete

}

public class NetheriteProviderFactory : IDurabilityProviderFactory
{
readonly static ConcurrentDictionary<(string taskhub, string storage, string transport), NetheriteProvider> CachedProviders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class NetheriteProviderStartup : IWebJobsStartup
public void Configure(IWebJobsBuilder builder)
{
#if !NETCOREAPP2_2
builder.Services.AddSingleton<IDurabilityProviderFactory, NetheriteProviderFactory>();
// We use the UnambiguousNetheriteProviderFactory class instead of the base NetheriteProviderFactory class
// to avoid ambiguous constructor errors during DI. More details for this workaround can be found in the UnambiguousNetheriteProviderFactory class.
builder.Services.AddSingleton<IDurabilityProviderFactory, UnambiguousNetheriteProviderFactory>();
builder.Services.TryAddSingleton<ConnectionResolver, NameResolverBasedConnectionNameResolver>();
#else
builder.Services.AddSingleton<IDurabilityProviderFactory, NetheriteProviderPseudoFactory>();
Expand Down
2 changes: 1 addition & 1 deletion src/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<MajorVersion>1</MajorVersion>
<MinorVersion>5</MinorVersion>
<PatchVersion>1</PatchVersion>
<PatchVersion>2</PatchVersion>
<VersionPrefix>$(MajorVersion).$(MinorVersion).$(PatchVersion)</VersionPrefix>
<VersionSuffix></VersionSuffix>
<AssemblyVersion>$(MajorVersion).0.0.0</AssemblyVersion>
Expand Down

0 comments on commit 928f933

Please sign in to comment.