Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I set a global object factory for Protobuf-net?

I see the SetFactory method on Protobuf-net. However, it appears to be available on per type basis. (And MethodInfo or a string? Can I hear it for Func<T>?)

What I want is the ability to use my IoC container's object resolution and construction abilities for all deserialization. (I'm using Autofac.) Protobuf-net should first attempt to use my IoC on any construction. If that returns null then I want the default behavior. Is there some way to do this currently? Thanks for your time.

like image 889
Brannon Avatar asked Jan 25 '13 23:01

Brannon


1 Answers

Not currently. The reason it doesn't take a delegate is that it aims to static-compile the model - MethodInfo is fine for that, but delegates: not so much. The factory method you supply, however, can take the serialization context which can contain whatever objects you need.

I could think about a default factory method - that sounds possible; I'll need to let one of the args be a Type, but that isn't a problem.

Would the ability to set "a default factory MethodInfo that can take (if it wants) a Type and a serialization-context" suffice?

like image 69
Marc Gravell Avatar answered Sep 28 '22 08:09

Marc Gravell