Spring.NET 1.3.0 RC1 for .NET 2.0 API Reference

IManagedCollection Interface

Denotes a special placeholder collection that may contain RuntimeObjectReferences or other placeholder objects that will need to be resolved.

For a list of all members of this type, see IManagedCollection Members .

[Visual Basic]
Public Interface IManagedCollection
    Implements ICollection, IEnumerable
[C#]
public interface IManagedCollection : ICollection, IEnumerable

Types that implement IManagedCollection

Type Description
ManagedDictionary Tag subclass used to hold a dictionary of managed elements.
ManagedList Tag subclass used to hold a list of managed elements.
ManagedSet Tag subclass used to hold a set of managed elements.

Remarks

'A special placeholder collection' means that the elements of this collection can be placeholders for objects that will be resolved later by a Spring.NET IoC container, i.e. the elements themselves will be resolved at runtime by the enclosing IoC container.

The core Spring.NET library already provides three implementations of this interface straight out of the box; they are...

If you have a custom collection class (i.e. a class that either implements the ICollection directly or derives from a class that does) that you would like to expose as a special placeholder collection (i.e. one that can have RuntimeObjectReferences as elements that will be resolved at runtime by an appropriate Spring.NET IoC container, just implement this interface.

Example

Lets say one has a Bag class (i.e. a collection that supports bag style semantics).

using System;

using Spring.Objects.Factory.Support;

namespace MyNamespace
{
    public sealed class Bag : ICollection
    {
        // ICollection implementation elided for clarity...
        
        public void Add(object o)
        {
            // implementation elided for clarity...
        }
    }
    
    public class ManagedBag : Bag, IManagedCollection
    {
        public ICollection Resolve(
            string objectName, RootObjectDefinition definition,
            string propertyName, ManagedCollectionElementResolver resolver)
        {
            Bag newBag = new Bag();
            string elementName = propertyName + "[bag-element]";
            foreach(object element in this)
            {
                object resolvedElement = resolver(objectName, definition, elementName, element);
                newBag.Add(resolvedElement);
            }
            return newBag;
        }
    }
}

Requirements

Namespace: Spring.Objects.Factory.Support

Assembly: Spring.Core (in Spring.Core.dll)

See Also

IManagedCollection Members | Spring.Objects.Factory.Support Namespace