Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (25 sloc) 917 Bytes
using System;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Host.Bindings;
namespace AutofacOnFunctions.Core.Services.Ioc
{
public class InjectAttributeBindingProvider : IBindingProvider
{
public Task<IBinding> TryCreateAsync(BindingProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var parameterInfo = context.Parameter;
var injectAttribute = parameterInfo.GetCustomAttribute<InjectAttribute>();
if (injectAttribute == null)
{
return Task.FromResult<IBinding>(null);
}
var objectResolver = ServiceLocator.Resolve<IObjectResolver>();
return Task.FromResult<IBinding>(new InjectAttributeBinding(parameterInfo, objectResolver));
}
}
}