yuka1984 / azure-functions-extensions-swashbuckle

MIT License
33 stars 29 forks source link

Extend to work with the new dependency injection extension from Microsoft #3

Open prabuw opened 5 years ago

prabuw commented 5 years ago

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.

yuka1984 commented 5 years ago

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

yuka1984 commented 5 years ago

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.

WolfyUK commented 4 years ago

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; }
    }
drdamour commented 4 years ago

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