Open lindydonna opened 7 years ago
I think this isn't currently possible, since we don't support DI. @fabiocav could you provide more info?
Looks like the function code is here. I can see the commented out service locator constructor call.
I removed the DI label because this looks more like an assembly loading issue.
@jsiegmund - most likely this is related to an autofac versionn mismatch. You need to use 4.2.1 (https://github.com/Azure/azure-webjobs-sdk-script/blob/dev/src/WebJobs.Script.WebHost/packages.config#L3)
I had the same problem (that the AutofacServiceLocator class would not be found at runtime but that all was fine at compile time). The workaround is to include a copy of https://github.com/autofac/Autofac.Extras.CommonServiceLocator/blob/develop/src/Autofac.Extras.CommonServiceLocator/AutofacServiceLocator.cs in your project.
I followed https://blog.kloud.com.au/2016/11/21/managing-dependencies-in-azure-functions/ but I'm using the precompiled approach - no .csx.
However that assembly loading issue is a problem indeed.
From @jsiegmund on July 3, 2017 19:39
I've created a Functions project which is set-up as a web project with the functions executable as 'start external program' as per @lindydonna 's instructions. So far so good, everything works. In the project I'm referencing a DLL from another project, also works fine.
Now I wanted to implement Autofac to do some dependency injection magic. So I added a NuGet reference to that project and created a ServiceLocator class for implementation. Now when I run my function, it fails stating it cannot find the Autofac ServiceLocator constructor. Very strange. Is there anything else I need to do in order to get these dependencies working? I checked the bin folder which holds all of the required DLLs.
For repro, get my code from https://github.com/jsiegmund/bots-domoticz. It currently also fails on a similar problem loading the Newtonsoft Json package.
Copied from original issue: Azure/azure-functions-cli#175