private void OnRegistering(object sender, ServiceRegisterEventArgs e)
        {
            if (e.ServiceType != typeof(PipelineManager))
            {
                ((AutofacServiceRegisterEventArgs)e).Registration.EnableClassInterceptors(new ProxyGenerationOptions
                {
                    Selector = new ServiceInterceptorSelector((IServiceContainer)sender)
                }).FindConstructorsWith(type =>
                {
#if NetCore
                    // Fix the constructor injection in the interception mechanism.
                    if (type.IsAssignableTo <IProxyTargetAccessor>())
                    {
                        var constructors = InjectionAttribute.GetConstructors(type.GetTypeInfo().BaseType).ToArray();
                        if (constructors.Length > 0)
                        {
                            return(constructors.Select(ctor => type.GetTypeInfo().GetConstructor(new[] { typeof(IInterceptor[]), typeof(IInterceptorSelector) }.Concat(ctor.GetParameters().Select(parameter => parameter.ParameterType)).ToArray())).ToArray());
                        }
                    }
                    return(type.GetConstructors());
#else
                    // Fix the constructor injection in the interception mechanism.
                    if (type.IsAssignableTo <IProxyTargetAccessor>())
                    {
                        var constructors = InjectionAttribute.GetConstructors(type.BaseType).ToArray();
                        if (constructors.Length > 0)
                        {
                            return(constructors.Select(ctor => type.GetConstructor(new[] { typeof(IInterceptor[]), typeof(IInterceptorSelector) }.Concat(ctor.GetParameters().Select(parameter => parameter.ParameterType)).ToArray())).ToArray());
                        }
                    }
                    return(type.GetConstructors());
#endif
                });
            }
        }
        public ConstructorInfo Find(Type pluggedType, DependencyCollection dependencies, PluginGraph graph)
        {
            var constructors = InjectionAttribute.GetConstructors(pluggedType).ToArray();

            if (constructors.Length == 0)
            {
                return(null);
            }
            return((from constructor in constructors
                    orderby constructor.GetParameters().Length descending
                    select constructor).FirstOrDefault());
        }
        private void Register(ContainerBuilder builder, Type serviceType, Type implementationType, string serviceName, ServiceLifetime lifetime)
        {
            var registration = serviceName == null
                ? builder.RegisterType(implementationType).As(serviceType)
                : builder.RegisterType(implementationType).Named(serviceName, serviceType);

            registration
            .FindConstructorsWith(type =>
            {
                var constructors = InjectionAttribute.GetConstructors(type).ToArray();
                if (constructors.Length > 0)
                {
                    return(constructors);
                }
#if NetCore
                return(type.GetTypeInfo().DeclaredConstructors.Where(ctor => !ctor.IsStatic && ctor.IsPublic).ToArray());
#else
                return(type.GetConstructors());
#endif
            })
            .UsingConstructor(new MostParametersConstructorSelector())
            .OnActivated(args => DynamicInjectionBuilder.GetOrCreate(implementationType, true, true)(this, args.Instance));
            OnRegistering(new AutofacServiceRegisterEventArgs(serviceType, implementationType, serviceName, lifetime, registration));
            switch (lifetime)
            {
            case ServiceLifetime.Singleton:
                registration.SingleInstance();
                break;

            case ServiceLifetime.Transient:
                registration.InstancePerDependency();
                break;

            case ServiceLifetime.PerThread:
                registration.RegistrationData.Sharing  = InstanceSharing.Shared;
                registration.RegistrationData.Lifetime = new PerThreadScopeLifetime();
                break;

            case ServiceLifetime.PerRequest:
                registration.RegistrationData.Sharing  = InstanceSharing.Shared;
                registration.RegistrationData.Lifetime = new PerRequestScopeLifetime(this);
                break;
            }
        }
        public virtual void ProcessModel(IKernel kernel, ComponentModel model)
        {
            var targetType   = model.Implementation;
            var constructors = InjectionAttribute.GetConstructors(targetType).Where(IsVisibleToContainer).ToArray();

            if (constructors.Length == 0)
            {
                constructors = targetType.GetConstructors(BindingFlags.Public | BindingFlags.Instance)
                               .Where(IsVisibleToContainer).ToArray();
            }

            foreach (var constructor in constructors)
            {
                // We register each public constructor
                // and let the ComponentFactory select an
                // eligible amongst the candidates later
                model.AddConstructor(CreateConstructorCandidate(model, constructor));
            }
        }