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

IOptions DI in Azure Function #991

Closed
ranouf opened this issue May 27, 2019 · 7 comments
Closed

IOptions DI in Azure Function #991

ranouf opened this issue May 27, 2019 · 7 comments

Comments

@ranouf
Copy link

ranouf commented May 27, 2019

Hi,

I would like to resolve IOptions using AzureFunctions.Autofac nuget package.

Usually in a webapi, we can use:

    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        [...]

        services.Configure<MySettings>(config.GetSection("My"));

        // Autofac
        var builder = new ContainerBuilder();
        builder.Populate(services);

        [...]
    }

But in an Azure function, the populate option is not available throw the nuget package Autofac.Extensions.DependencyInjection:
image

How are you available to access to IOptions in Azure function using Autofac DI?

Thanks for your help.

@tillig
Copy link
Member

tillig commented May 27, 2019

It appears the AzureFunctions.Autofac package has forced an exact version match for core Autofac. I can't tell you why, but that's the problem.

AzureFunctions.Autofac is not owned by the Autofac organization. Contact the owners through their NuGet page.

@tillig tillig closed this as completed May 27, 2019
@ranouf
Copy link
Author

ranouf commented May 27, 2019

Thanks for the information @tillig !

@ranouf
Copy link
Author

ranouf commented May 27, 2019

If I want to use only Autofac nuget, do you have sample on how to use it with Azure Function?

@tillig
Copy link
Member

tillig commented May 27, 2019

No, sorry. There may be stuff on StackOverflow or Google.

@ranouf
Copy link
Author

ranouf commented May 29, 2019

Hi @tillig

I found this:
https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection

It s pretty new, it s the official way to do DI in Azure Function, but from I read on different forums, it seems not possible to use Autofac with it:

Is there a way to use Autofac using the new microsoft DI implementation ?

@tillig
Copy link
Member

tillig commented May 29, 2019

I have no experience using Azure Functions and, unfortunately, no time at the moment to become an expert and research this for you. Your best bet is to check out StackOverflow and/or maybe ping the authors of AzureFunctions.Autofac. You may also try to determine the best route by looking at some of our other integrations, like the one for Service Fabric or something to give you ideas... but I can't even point you in the right direction because I've never used Azure Functions. It looks like the issues you linked may be good places to follow up, too.

@ranouf
Copy link
Author

ranouf commented May 29, 2019

Thanks, I will :)

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

No branches or pull requests

2 participants