I'm trying to use dependency injection with Azure Functions v3. I've used the Startup approach as recommended by Microsoft in the following article:-
https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection
The event is firing correctly which is great. I'm then calling a dependency resolution helper I use across multiple project types.
I use Scrutor to scan the assemblies so that I don't have to manually add each interface to a class (AddTransient, etc). This works great in an ASP.NET Core Web API project, but does not work at all with an Azure Function. My solution dependencies are not being added at all.
This is the code I have:-
public static void AddSolutionServices(this IServiceCollection services)
{
services.Scan(scan => scan
.FromCallingAssembly()
.FromApplicationDependencies()
.AddClasses(classes => classes.Where(types => types.FullName.StartsWith("MyNamespace.")))
.UsingRegistrationStrategy(RegistrationStrategy.Append)
.AsMatchingInterface()
.WithTransientLifetime()
);
}
This is the first time I've tried to write an Azure function so I'm wondering if it's not possible to use assembly scanning with this type of application. Any help would be appreciated!
Thanks
UPDATE 08/09/2020
I still had problems using Scrutor for assembly scanning, something to do with the way dlls are loaded at runtime I believe but I'm not 100% sure on this. I ended up having to manually register services/types as per the standard Microsoft documentation. Scrutor was able to work everywhere else but not for Azure Functions. I'm hoping I was doing something wrong but was unable to find a solution.