in src/TriggersBinding/MySqlTriggerBindingProvider.cs [49:96]
public Task<ITriggerBinding> TryCreateAsync(TriggerBindingProviderContext context)
{
if (context == null)
{
}
ParameterInfo parameter = context.Parameter;
MySqlTriggerAttribute attribute = parameter.GetCustomAttribute<MySqlTriggerAttribute>(inherit: false);
// During application startup, the WebJobs SDK calls 'TryCreateAsync' method of all registered trigger
// binding providers in sequence for each parameter in the user function. A provider that finds the
// parameter-attribute that it can handle returns the binding object. Rest of the providers are supposed to
// return null. This binding object later gets used for binding before every function invocation.
if (attribute == null)
{
return Task.FromResult<ITriggerBinding>(null);
}
Type parameterType = parameter.ParameterType;
if (!IsValidTriggerParameterType(parameterType))
{
throw new InvalidOperationException($"Can't bind MySqlTriggerAttribute to type {parameter.ParameterType}, this is not a supported type.");
}
string connectionString = MySqlBindingUtilities.GetConnectionString(attribute.ConnectionStringSetting, this._configuration);
Type bindingType;
// Instantiate class 'MySqlTriggerBinding<JObject>' for non .NET In-Proc functions.
if (parameterType == typeof(string))
{
bindingType = typeof(MySqlTriggerBinding<>).MakeGenericType(typeof(JObject));
}
else
{
// Extract the POCO type 'T' and use it to instantiate class 'SqlTriggerBinding<T>'.
Type userType = parameter.ParameterType.GetGenericArguments()[0].GetGenericArguments()[0];
bindingType = typeof(MySqlTriggerBinding<>).MakeGenericType(userType);
}
var constructorParameterTypes = new Type[] { typeof(string), typeof(string), typeof(string), typeof(ParameterInfo), typeof(IOptions<MySqlOptions>), typeof(ILogger), typeof(IConfiguration) };
ConstructorInfo bindingConstructor = bindingType.GetConstructor(constructorParameterTypes);
object[] constructorParameterValues = new object[] { connectionString, attribute.TableName, attribute.LeasesTableName, parameter, this._mysqlOptions, this._logger, this._configuration };
var triggerBinding = (ITriggerBinding)bindingConstructor.Invoke(constructorParameterValues);
return Task.FromResult(triggerBinding);
}