Skip to content

NServiceBus does not collaborate properly with ServiceCollection provided by Azure Functions  #92

@SeanFeldman

Description

@SeanFeldman

Describe the problem

When trying to use NServiceBus for Azure Functions and register Entity Framework (EF) into the container, get the following exception:

Unable to resolve service for type 'Microsoft.Azure.WebJobs.Script.IEnvironment' while attempting to activate 
  'Microsoft.Azure.WebJobs.Script.Configuration.ScriptHostOptionsSetup'.

After raising the Azure/azure-functions-host#6783 issue with Azure Functions it became apparent that the way NServiceBus.AzureFunctions is leveraging the ServiceCollection is wrong for both the static and non-static usages.

When instantiating an NServiceBus.AzureFunctions FunctionEndpoint using the static approach, the ServiceCollection does not share any services/components with Azure Functions SDK. When instantiating an NServiceBus.AzureFunctions FunctionEndpoint using the non-static approach using DI, the ServiceCollection that we get in the Startup class to configure services is a subset of all the services. Regardless of the approach, the service provider built by NServiceBus will not contain all the dependencies.

Potential workaround

Not possible with the current implementation.

Potential solutions

The NServiceBus.AzureFunctions implementation needs to treat the Azure Functions hosted endpoint as an endpoint with an externally-managed container, using the service collection and service provider supplied by Azure Functions. This means using the DI style of Functions and not the static implementation, providing an extension method such as .UseNServiceBus(...). This extension method would be used to configure the FunctionEndpoint.

Additional information to help with this issue

I've created a repository with all of the findings

Summary

This issue prevents the adoption of NServiceBus.AzureFunctions when 3rd party dependencies fail to be resolved.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions