Creating unity configuration using the unity object model

Jul 8, 2008 at 8:55 AM
I have this class

    public class SerializableUnityConfiguration : UnityConfigurationSection
    {
        public const string UnityConfigurationName = "unity";
        public void ReadConfiguration(XmlReader reader)
        {
            reader.Read();
            DeserializeSection(reader);
        }

        public void WriteConfiguration(XmlWriter writer)
        {
            String serialized = SerializeSection(this, UnityConfigurationName, ConfigurationSaveMode.Full);
            writer.WriteRaw(serialized);
        }

        public XmlReader GetReader()
        {
            String serialized = SerializeSection(this, UnityConfigurationName, ConfigurationSaveMode.Full);

            StringReader strReader = new StringReader(serialized);

            return XmlReader.Create(strReader);

        }
    }

this class enables me to serialize and deserialize unity configuration.

now my problem is how can i creat unity configuration using unity object model. i had look at the configuration source code and can't find methods to add a new UnityContainerElement to the UnityContainerElementCollection.

I know i can read configuration pre-created in a .config file, i'm wondering how can i create and configuration by hand and the serialize this configuration, ex: to a file or to a database.

Pedro Rainho