azure-functions-extensions-swashbuckle icon indicating copy to clipboard operation
azure-functions-extensions-swashbuckle copied to clipboard

Extend to work with the new dependency injection extension from Microsoft

Open prabuw opened this issue 5 years ago • 4 comments

The AddSwashbuckle extension method to be used on start up depends on working with IWebJobsBuilder. However, this doesn't work with the new dependency injection extension released from Microsoft. It comes with IFunctionsHostBuilder.

Can we add another extension to allow it to work with the IFunctionsHostBuilder? I'm happy to discuss the approach and raise a PR if you are open to a contribution.

prabuw avatar May 30 '19 13:05 prabuw

@prabuw Thank you for the report. I add an extension method to IFunctionsHostBuilder.

yuka1984 avatar Jun 20 '19 17:06 yuka1984

Hi @prabuw . Thank you issue.

IFunctionHostBuilder is Azure Functions DI point. But it is not support AddExtension extension method. https://github.com/yuka1984/azure-functions-extensions-swashbuckle/blob/master/src/AzureFunctions.Extensions.Swashbuckle/AzureFunctions.Extensions.Swashbuckle/SwashBuckleStartupExtension.cs#L19

if IFunctionsHostBulder support AddExtension method, I can support it.

yuka1984 avatar Jun 20 '19 18:06 yuka1984

My workaround for this is as follows (v1.4.4):

    public class Startup : IWebJobsStartup
    {
        public void Configure(IWebJobsBuilder builder)
        {
            builder.AddSwashBuckle(Assembly.GetExecutingAssembly());
            Configure(new FunctionsHostBuilder(builder.Services));
        }

        private static void Configure(IFunctionsHostBuilder builder)
        {
            // register other services here
        }
    }
    
    internal class FunctionsHostBuilder : IFunctionsHostBuilder
    {
        public FunctionsHostBuilder(IServiceCollection services)
        {
            var serviceCollection = services;
            Services = serviceCollection ?? throw new ArgumentNullException(nameof (services));
        }

        public IServiceCollection Services { get; }
    }

WolfyUK avatar Dec 16 '19 08:12 WolfyUK

nice workaround, it might be better to go the other way since IFunctionsHostBuilder is the new hotness, fake up an IWebJobsStartup by passing in services and calling the existing extension on it

drdamour avatar Jun 10 '20 21:06 drdamour