Example #1
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ProxyPart"/> class.
		/// </summary>
		/// <param name="registration">The registration</param>
		/// <param name="innerPart">The inner part.</param>
		public ProxyPart(ComponentRegistrationBase registration, ComposablePart innerPart)
		{
			implementation = GetImplementation(registration);
			this.registration = registration;
			this.innerPart = innerPart;
			DeterminePropertiesToInject();
		}
Example #2
0
        public InstanceLookup(
            IComponentRegistration registration,
            IResolveOperation context,
            ISharingLifetimeScope mostNestedVisibleScope,
            IEnumerable<Parameter> parameters)
        {
            Parameters = parameters;
            ComponentRegistration = registration;
            _context = context;

            try
            {
                _activationScope = ComponentRegistration.Lifetime.FindScope(mostNestedVisibleScope);
            }
            catch (DependencyResolutionException ex)
            {
                var services = new StringBuilder();
                foreach (var s in registration.Services)
                {
                    services.Append("- ");
                    services.AppendLine(s.Description);
                }

                var message = String.Format(CultureInfo.CurrentCulture, ComponentActivationResources.UnableToLocateLifetimeScope, registration.Activator.LimitType, services);
                throw new DependencyResolutionException(message, ex);
            }
        }
 protected override void AttachToComponentRegistration(IComponentRegistry registry, IComponentRegistration registration)
 {
   registration.Preparing += (s, e) =>
   {
     e.Parameters = new [] { loggerParameter }.Concat(e.Parameters);
   };
 }
		protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry,
			IComponentRegistration registration)
		{
			registration.Preparing += RegistrationOnPreparing;
			registration.Activating += RegistrationOnActivating;
			base.AttachToComponentRegistration(componentRegistry, registration);
		}
 protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
 {
     registration.Preparing += (sender, args) =>
         {
             args.Parameters = args.Parameters.Union( new[] { new NamedParameter(@"basePoint", _basePoint) } );
         };
 }
Example #6
0
        protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
        {
            var implementationType = registration.Activator.LimitType;

            foreach (var autoWireType in autoWireTypes)
            {
                var constructors = implementationType.GetConstructorsWithDependency(autoWireType);

                if (constructors.Any())
                {
                    registration.Preparing += (sender, e) =>
                    {
                        var parameter = new TypedParameter(autoWireType,
                            e.Context.Resolve(autoWireType, new TypedParameter(typeof(Type), implementationType)));
                        e.Parameters = e.Parameters.Concat(new[] { parameter });
                    };
                }
                else
                {
                    var props = implementationType.GetPropertiesWithDependency(autoWireType);
                    if (props.Any())
                    {
                        registration.Activated += (s, e) =>
                        {
                            foreach (var prop in props)
                            {
                                prop.SetValue(e.Instance,
                                    e.Context.Resolve(autoWireType));
                            }
                        };
                    }
                }
            }

            foreach (var serviceType in typebasedServiceTypes)
            {
                var constructorInjectors = BuildConstructorServiceInjectors(implementationType, serviceType).ToArray();
                if (constructorInjectors.Any())
                {
                    registration.Preparing += (s, e) =>
                    {
                        foreach (var ci in constructorInjectors)
                            ci(e);
                    };
                    return;
                }

                // build an array of actions on this type to assign loggers to member properties
                var injectors = BuildPropertyServiceInjectors(implementationType, serviceType).ToArray();

                if (injectors.Any())
                {
                    registration.Activated += (s, e) =>
                    {
                        foreach (var injector in injectors)
                            injector(e.Context, e.Instance);
                    };
                }
            }
        }
Example #7
0
		/// <summary>
		/// Initializes a new instance of the <see cref="PreparingEventArgs"/> class.
		/// </summary>
		/// <param name="service">Service which is preparing</param>
		/// <param name="context">The context.</param>
		/// <param name="component">The component.</param>
		/// <param name="parameters">The parameters.</param>
		public PreparingEventArgs(Service service, IComponentContext context, IComponentRegistration component, IEnumerable<Parameter> parameters)
		{
			_service = Enforce.ArgumentNotNull(service, "service");
			_context = Enforce.ArgumentNotNull(context, "context");
			_component = Enforce.ArgumentNotNull(component, "component");
			_parameters = Enforce.ArgumentNotNull(parameters, "parameters");
		}
    protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
    {
      var type = registration.Activator.LimitType;  //  AF2.0+
      //  .Descriptor.BestKnownImplementationType;  //  AF1.2+

      //  we hook preparing to inject the logger into the constructor
      registration.Preparing += OnComponentPreparing;

      // build the list of actions for type and assign loggers to properties
      var injectors = BuildLogPropertyInjectors(type);

      // no logger properties, no need to hook up the event
// ReSharper disable PossibleMultipleEnumeration
      if (!injectors.Any())
// ReSharper restore PossibleMultipleEnumeration
        return;

      // we hook acticating to inject the logger into the known public properties
      registration.Activating += (s, e) =>
      {
// ReSharper disable PossibleMultipleEnumeration
        foreach (var injector in injectors)
// ReSharper restore PossibleMultipleEnumeration
          injector(e.Context, e.Instance);
      };
    }
 protected override void AttachToComponentRegistration(
     IComponentRegistry componentRegistry,
     IComponentRegistration registration)
 {
     registration.Preparing += (sender, args) =>
         log.Debug([email protected]"Resolving concrete type {args.Component.Activator.LimitType}");
 }
 public ShapeAttributeOccurrence(ShapeAttribute shapeAttribute, MethodInfo methodInfo, IComponentRegistration registration, Func<Feature> feature)
 {
     ShapeAttribute = shapeAttribute;
     MethodInfo = methodInfo;
     Registration = registration;
     _feature = feature;
 }
 protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
 {
     registration.Activating += (sender, e) =>
     {
         if (typeof (IMessageConsumer).IsAssignableFrom(e.Instance.GetType()))
             consumerInterceptor.ItemCreated(e.Instance.GetType(), e.Component.Lifetime.GetType().Equals(typeof(CurrentScopeLifetime)));
     };
 }
		protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
		{
			registration.Preparing += (sender, args) => args.Parameters = args.Parameters.Concat(new[]
			{
				new ResolvedParameter((info, context) => info.ParameterType == typeof (ILog),
					(info, context) => _logFactory(info.Member.DeclaringType))
			});
		}
        public ComponentRegistrationLifetimeDecorator(IComponentRegistration inner, IComponentLifetime lifetime)
        {
            if (inner == null) throw new ArgumentNullException("inner");
            if (lifetime == null) throw new ArgumentNullException("lifetime");

            _inner = inner;
            _lifetime = lifetime;
        }
Example #14
0
        protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
        {
            // Handle constructor parameters.
            registration.Preparing += OnComponentPreparing;

            // Handle properties.
            registration.Activated += (sender, e) => InjectLoggerProperties(e.Instance);
        }
        static IEnumerable<Parameter> AddDecoratedComponentParameter(Type decoratedParameterType, IComponentRegistration decoratedComponent, IEnumerable<Parameter> configuredParameters)
        {
            var parameter = new ResolvedParameter(
                (pi, c) => pi.ParameterType == decoratedParameterType,
                (pi, c) => c.ResolveComponent(decoratedComponent, Enumerable.Empty<Parameter>()));

            return new[] { parameter }.Concat(configuredParameters);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ComponentRegisteredEventArgs"/> class.
        /// </summary>
        /// <param name="registry">The container into which the registration
        /// was made.</param>
        /// <param name="componentRegistration">The component registration.</param>
        public ComponentRegisteredEventArgs(IComponentRegistry registry, IComponentRegistration componentRegistration)
        {
            if (registry == null) throw new ArgumentNullException(nameof(registry));
            if (componentRegistration == null) throw new ArgumentNullException(nameof(componentRegistration));

            ComponentRegistry = registry;
            ComponentRegistration = componentRegistration;
        }
 protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
 {
     // Use the event args to log detailed info
     registration.Preparing += (sender, args) =>                      
         Debug.WriteLine(
             "Resolving concrete type {0}, Id {1}",
             args.Component.Activator.LimitType, args.Component.Id.ToString());
 }
 protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
 {
     Type implementationType = registration.Activator.LimitType;
     if (DynamicProxyContext.From(registration) != null && implementationType.FullName == "Orchard.Car.Services.CarInfoService")
     {
         registration.InterceptedBy<SimpleInterceptor>();
     }
 }
		public void RecordActivation(IComponentRegistration component)
		{
			lock (_synchRoot)
			{
				var componentInfo = GetComponent(component.Id);
				componentInfo.RecordActivation();
			}
		}
		protected override void AttachToComponentRegistration(
			IContainer container, IComponentRegistration registration)
		{
			base.AttachToComponentRegistration(container, registration);

			var registeredType = registration.Descriptor.BestKnownImplementationType;
			if (IsConfiguredTransport(registeredType))
				DecorateTransport(container, registeredType);
		}
Example #21
0
        protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
        {
            var implementationType = registration.Activator.LimitType;
            var property = FindProperty(implementationType);

            if (property != null) {
                registration.InterceptedBy<ISecurityModuleInterceptor>();
            }
        }
 /// <summary>
 /// Override to attach module-specific functionality to a
 /// component registration.
 /// </summary>
 /// <remarks>This method will be called for all existing <i>and future</i> component
 /// registrations - ordering is not important.</remarks>
 /// <param name="componentRegistry">The component registry.</param>
 /// <param name="registration">The registration to attach functionality to.</param>
 protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
 {
     if (registration == null)
     {
         throw new ArgumentNullException("registration");
     }
     foreach (var property in MetadataHelper.GetMetadata(registration.Activator.LimitType))
         registration.Metadata.Add(property);
 }
		public DependencyTrackingContext(
			ContainerProfile profile,
			IComponentRegistration registration,
			IComponentContext context)
		{
			_profile = profile;
			_registration = registration;
			_context = context;
		}
Example #24
0
 /// <summary>
 /// Attempts to find a default registration for the specified service.
 /// </summary>
 /// <param name="service">The service to look up.</param>
 /// <param name="registration">The default registration for the service.</param>
 /// <returns>True if a registration exists.</returns>
 public bool TryGetRegistration(Service service, out IComponentRegistration registration)
 {
     if (service == null) throw new ArgumentNullException("service");
     lock (_synchRoot)
     {
         var info = GetInitializedServiceInfo(service);
         return info.TryGetRegistration(out registration);
     }
 }
Example #25
0
        protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
        {
            base.AttachToComponentRegistration(componentRegistry, registration);

            if (registration.Activator.LimitType.IsAssignableTo<IHandle>())
            {
                registration.Activated += RegistrationOnActivated;
            }
        }
		public ProfilingActivator(
			IComponentRegistration registration,
			IInstanceActivator innerActivator,
			ContainerProfile profile)
		{
			_registration = registration;
			_innerActivator = innerActivator;
			_profile = profile;
		}
        public IEnumerable<ParameterInfo> GetRegistrationCtorParameters(IComponentRegistration componentRegistration)
        {
            var activator = componentRegistration.Activator as ReflectionActivator;
            if (activator == null)
                return Enumerable.Empty<ParameterInfo>();

            var limitType = activator.LimitType;
            return activator.ConstructorFinder.FindConstructors(limitType).SelectMany(ctor => ctor.GetParameters());
        }
Example #28
0
        protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration) {

            if (!registration.Services.Contains(new TypedService(typeof(ICommandHandler))))
                return;

            var builder = new CommandHandlerDescriptorBuilder();
            var descriptor = builder.Build(registration.Activator.LimitType);
            registration.Metadata.Add(typeof(CommandHandlerDescriptor).FullName, descriptor);
        }
        private ServiceHost CreateServiceHost(IWorkContextAccessor workContextAccessor, IComponentRegistration registration, Type implementationType, Uri[] baseAddresses) {
            ServiceHost host = CreateServiceHost(implementationType, baseAddresses);

            host.Opening += delegate {
                host.Description.Behaviors.Add(new OrchardDependencyInjectionServiceBehavior(workContextAccessor, implementationType, registration));
            };

            return host;
        }
Example #30
0
        public override void Register(IComponentRegistration registration, bool preserveDefaults)
        {
            var toRegister = registration;

            if (registration.Lifetime is RootScopeLifetime)
                toRegister = new ComponentRegistrationLifetimeDecorator(registration, _restrictedRootScopeLifetime);

            base.Register(toRegister, preserveDefaults);
        }