protected override void VisitEnumerableParameterValue(ContainerResolvedEnumerableParameter parameterValue) { string typeName = parameterValue.ElementType.Name; ManagedList listVal = new ManagedList(); listVal.ElementTypeName = parameterValue.ElementType.AssemblyQualifiedName; foreach (string name in parameterValue.Names) { listVal.Add(new RuntimeObjectReference(String.Concat(name,".",typeName))); } InjectionParameter = listVal; }
/// <summary> /// The method called when a <see cref="T:Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ContainerResolvedEnumerableParameter"/> object is visited. /// </summary> /// <param name="parameterValue">The <see cref="T:Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ContainerResolvedEnumerableParameter"/> to process.</param> protected override void VisitEnumerableParameterValue(ContainerResolvedEnumerableParameter parameterValue) { InjectionParameters = parameterValue.Names .Select(name => Property.ForKey(parameterValue.ElementType).Is(name)) .ToArray(); }
/// <summary> /// The method called when a <see cref="ContainerResolvedEnumerableParameter"/> object is visited. /// </summary> /// <remarks>By default, this method throws an exception. Override it to provide your /// specific processing.</remarks> /// <param name="parameterValue">The <see cref="ContainerResolvedEnumerableParameter"/> to process.</param> protected virtual void VisitEnumerableParameterValue(ContainerResolvedEnumerableParameter parameterValue) { VisitParameterValue(parameterValue); }
/// <summary> /// The method called when a /// <see cref="T:Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ContainerResolvedEnumerableParameter"/> /// object is visited. /// </summary> /// <param name="parameterValue"> /// The <see cref="T:Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ContainerResolvedEnumerableParameter"/> to process. /// </param> /// <remarks> /// <para> /// Resolved enumerables in Enterprise Library are always made up of /// a list of individual named resolutions - there is no notion of a /// typed auto-collection resolution the way there is in Autofac. /// </para> /// <para> /// As such, the <see cref="Autofac.Core.ResolvedParameter"/> lambda /// this method generates is a loop over the set of resolved named /// typed registrations to build them manually into a list of the /// type specified. /// </para> /// </remarks> /// <exception cref="System.ArgumentNullException"> /// Thrown if <paramref name="parameterValue" /> is <see langword="null" />. /// </exception> protected override void VisitEnumerableParameterValue(ContainerResolvedEnumerableParameter parameterValue) { if (parameterValue == null) { throw new ArgumentNullException("parameterValue"); } this.AutofacParameter = this.CreateResolvedParameter( (pi, context) => { var listType = typeof(List<>).MakeGenericType(parameterValue.ElementType); var list = Activator.CreateInstance(listType) as IList; foreach (var name in parameterValue.Names) { list.Add(context.ResolveNamed(name, parameterValue.ElementType)); } return list; }); }