Serialization flexibility comment

Jul 29, 2009 at 7:21 PM
Edited Jul 29, 2009 at 8:01 PM

Due to XmlSerializer limitation to work with interfaces we are using DataContractSerializer, which has some specifics we would like to overcome. We would like to have more control over serialized/deserialized datatypes. DataContractSerializer has a parameter implementing IDataContractSurrogate, in which we see resolution of the problem.

I do not see how to use advantages of it in current implementation of SimpleServiceBus.Bus.MessageManagment.Serialization.DataContractMessageSerializer. Due to our integration with WindsorCastle container I implemented public property of type IDataContractSurrogate, which is resolved by IoC, but it would not work whithout dependency injection.

Would be great to have such functionality implemented not depending on any IoC. Could you give some feedback or implementation tips for this.


PS: Here is change in DataContractMessageSerializer class

        public IDataContractSurrogate DataContractSurrogate { get; set; }

        private void Initialize()
            var messageTypes = new List<Type> {typeof (object)};
            if (_knownTypes != null)

            var msgMgr = ServiceManager.GetService<IMessageTypeManagementService>();
            if (msgMgr != null)

            _xmlMessageSerializer = new DataContractSerializer(typeof(object), messageTypes.ExtractSerializableTypes(), int.MaxValue, false, true, DataContractSurrogate);