microsoft / service-fabric-aspnetcore

This repo contains ASP.NET Core integration for Service Fabric Reliable Services.
Other
152 stars 49 forks source link

ServiceFabricIntegrationOptions UseUniquestServiceUrl is not possible using IHostBuilder outside this assemble #99

Closed jwyglendowski-precisionlender closed 2 years ago

jwyglendowski-precisionlender commented 2 years ago

Describe the bug AspNetCoreCommunicationListener has the option ConfigureToUseUniqueServiceUrl which is an internal method called by WebHostBuilderServiceFabricExtension.cs if the ServiceFabricIntegrationOptions UseUniquestServiceUrl is set to true. The IHost was added to KestrelCommunicationListener which inherits from AspNetCoreCommunicationListener. There is test for uniqueness option with AspNetCoreCommunicationListenerTests which is used by the Kestrel Tests. The bug is that since the test is part of the same assembly it can call the internal method ConfigureToUseUniqueServiceUrl but since there is no Extension for IHostBuilder there is no way to implement an extension to call this method.

To Reproduce Implement your own Host Builder extension using KestrelCommunicationListener like the following and see that the method in question is not accessible.

public static IHostBuilder UseServiceFabricIntegration(this IHostBuilder hostBuilder,
            KestrelCommunicationListener listener,            
            Runtime.ServiceFabricIntegrationOptions options)
{
    if (hostBuilder == null)
    {
        throw new ArgumentNullException(nameof(hostBuilder));
    }
    if (listener == null)
    {
        throw new ArgumentNullException(nameof(listener));
    }
    // use environmental variable to replace this logic
    // // Check if 'UseServiceFabricIntegration' has already been called.
    if (listener.HasUseServiceFabricIntegrationBeenCalled) return hostBuilder;

    // // Set flag to prevent double service configuration
    listener.HasUseServiceFabricIntegrationBeenCalled = true;

    if (options.HasFlag(Runtime.ServiceFabricIntegrationOptions.UseUniqueServiceUrl))
    {
        listener.ConfigureToUseUniqueServiceUrl();
    }

    hostBuilder.ConfigureServices((services) =>
    {
        services.AddSingleton<IStartupFilter>(new ServiceFabricSetupFilter(listener.UrlSuffix, options));
    });

    return hostBuilder;
}

Expected behavior Expose this method so that it accessible through inheritance or create a new Extension Method for IHostBuilder.

Additional context During a previous upgrade several years ago to .net core 3.1 we just implemented our own listener to emulate the KestrelCommunicationListener and added IHost and IHostBuilder functionality and now that we are migrating to NET6 we would like to not to have to do this again. This is similar in nature to Issue 48 but I believe this is not a feature request because to the for mentioned issue. It would seem that it would take five minutes to create a new extension method to accomplish this.

jwyglendowski-precisionlender commented 2 years ago

I found the documentation and am linking to it here in case someone else runs into the problem.

https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-aspnetcore#ihost-and-minimal-hosting-integration

jwyglendowski-precisionlender commented 2 years ago

The extension method is not needed based on the referenced documentation.