public Task <IBinding> TryCreateAsync(BindingProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            //Get the resolver starting with method then class
            MethodInfo method = context.Parameter.Member as MethodInfo;
            DependencyInjectionConfigAttribute attribute = method.DeclaringType.GetCustomAttribute <DependencyInjectionConfigAttribute>();

            if (attribute == null)
            {
                throw new MissingAttributeException();
            }

            var functionName = method.DeclaringType.Name;

            //Initialize DependencyInjection
            var functionAndAppDirectoryAndLoggerFactoryConstructor = attribute.Config.GetConstructor(new[] { typeof(string), typeof(string), typeof(ILoggerFactory) });
            var functionAndAppLoggerFactoryConstructor             = attribute.Config.GetConstructor(new[] { typeof(string), typeof(ILoggerFactory) });
            var functionAndAppDirectoryConstructor = attribute.Config.GetConstructor(new[] { typeof(string), typeof(string) });

            if (functionAndAppDirectoryAndLoggerFactoryConstructor != null)
            {
                Activator.CreateInstance(attribute.Config, functionName, _appDirectory, _loggerFactory);
            }
            else if (functionAndAppDirectoryConstructor != null)
            {
                Activator.CreateInstance(attribute.Config, functionName, _appDirectory);
            }
            else if (functionAndAppLoggerFactoryConstructor != null)
            {
                Activator.CreateInstance(attribute.Config, functionName, _loggerFactory);
            }
            else
            {
                Activator.CreateInstance(attribute.Config, functionName);
            }

            //Check if there is a name property
            InjectAttribute injectAttribute = context.Parameter.GetCustomAttribute <InjectAttribute>();
            //This resolves the binding
            IBinding binding = new InjectBinding(context.Parameter.ParameterType, injectAttribute.Name, functionName);

            return(Task.FromResult(binding));
        }
コード例 #2
0
        public Task <IBinding> TryCreateAsync(BindingProviderContext context)
        {
            //Get the resolver starting with method then class
            MethodInfo method = context.Parameter.Member as MethodInfo;
            DependencyInjectionConfigAttribute attribute = method.DeclaringType.GetCustomAttribute <DependencyInjectionConfigAttribute>();

            if (attribute == null)
            {
                throw new MissingAttributeException();
            }
            //Initialize DependencyInjection
            Activator.CreateInstance(attribute.Config);
            //Check if there is a name property
            InjectAttribute injectAttribute = context.Parameter.GetCustomAttribute <InjectAttribute>();
            //This resolves the binding
            IBinding binding = new InjectBinding(context.Parameter.ParameterType, injectAttribute.Name);

            return(Task.FromResult(binding));
        }