Для всех, кто интересуется, WebJobsStartup и связанные типы можно найти в пакете NuGet «Microsoft.Azure.WebJobs.Extensions».
пользуем внедрение зависимостей в нашей функции Azure (v2 на netstandard20), используя привязку параметров с IExtensionConfigProvider. После обновления Microsoft.NET.Sdk.Functions с версии 1.0.13 до 1.0.19 (что привело к обновлению Microsoft.Azure.Webjobs.Host до версии 3) это больше не работает. Я больше не могу достичь точки останова в моей функции IExtensionConfigProvider.Initialize. Та же версия Functions SDK отлично работает для примера проекта с целевой платформой net462, для которой он использует Microsoft.Azure.WebJobs v2.
Вот ошибка, которую это дает во время выполнения:
Ошибка индексации метода «Function1.Run». Microsoft.Azure.WebJobs.Host: Невозможно привязать параметр 'customThing' к типу CustomType. Убедитесь, что параметр Type поддерживается привязкой.
А вот код для примера приложения:
public static class Function1
{
[FunctionName("ThisFunction")]
public static async Task Run(
[TimerTrigger("0 */1 * * * *")]TimerInfo timer,
[Inject(typeof(CustomType))] CustomType customThing,
ExecutionContext context)
{
Console.WriteLine(customThing.GetMessage());
}
}
public class CustomType
{
public string GetMessage() => "Hi";
}
[Binding]
[AttributeUsage(AttributeTargets.Parameter)]
public class InjectAttribute : Attribute
{
public Type Type { get; }
public InjectAttribute(Type type) => Type = type;
}
public class InjectConfiguration : IExtensionConfigProvider
{
private IServiceProvider _serviceProvider;
public void Initialize(ExtensionConfigContext context)
{
var services = new ServiceCollection();
services.AddSingleton<CustomType>();
_serviceProvider = services.BuildServiceProvider(true);
context
.AddBindingRule<InjectAttribute>()
.BindToInput<dynamic>(i => _serviceProvider.GetRequiredService(i.Type));
}
}