1
votes

I am do I migration to .standard to .core, but I faced a problem:

Microsoft.Azure.WebJobs.Host: Error indexing method 'FunctionName'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'MyService' to type IMyService. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

I am using a startup with autofac to resolve the dependency

 public sealed class Startup : IExtensionConfigProvider
    {
        private static IContainer container;

        public void Initialize(ExtensionConfigContext context)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType<MyService>().As<IMyToCoreService>().InstancePerDependency();

            container = builder.Build();

            context.AddBindingRule<InjectAttribute>().BindToInput<dynamic>(inject => container.Resolve(inject.Type));
        }
    }

The NuGets are:

Autofac - 4.9.0
Microsoft.Azure.WebJobs.Extensions.Storage - 3.0.3
Microsoft.NET.Sdk.Functions 1.0.24

And the function:

public static async Task RunAsync([QueueTrigger(ASERVICETOGETANAME)]string blobInformation,
            [Inject(typeof(IMyService))]IMyService myService, 
            ILogger log, CancellationToken cancellationToken)

I try to downgrade the versions of nuget and .net core, but I didnt have any success, what more can I do resolve the dependency problem?

EDIT - The Startup class is not being called.

1
I have had a lot of issues doing this, create a new blank .net core functions app and copy your code over. At face value it seems tedious but it seems to end up quicker in the long run.Murray Foxcroft
@MurrayFoxcroft I did :/ , I am think it is related to the sdk.funtions version beacause the QueueTrigger was migrated to separated libraryHudsonPH
You do need to upgrade across the board.Murray Foxcroft

1 Answers

0
votes

I found a solution,

install the nugget AzureFunctions.Autofac

add [DependencyInjectionConfig(typeof(Startup))] in your function class.

on the startup class, make a construct passing a string :

public Startup(string functionName)
{
    Initialize(functionName);
}

on the Initialize:

 public void Initialize(string functionName)
 {
      DependencyInjection.Initialize(builder =>
      {
       // your injections
      }, functionName);

  }