6

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.

Brannon
  • 5,324
  • 4
  • 35
  • 83

1 Answers1

2

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?

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • 2
    @Brannon committed in r626, with [example/test here](https://github.com/mgravell/protobuf-net/blob/59b83356149a6df5027631421e2d6e03c8708725/src/Examples/Issues/SO14532116.cs) – Marc Gravell Jan 29 '13 at 09:55
  • Marc, protobuf does not seem to use the default factory on classes that are explicitly added to the RuntimeTypeModel. This means I cannot use the IOC container to resolve them. Is this by design? – anakic Jul 05 '13 at 08:08
  • @AntonioNakicAlfirevic do you mean added explicitly with `false` for `applyDefaultBehavior`? Interesting - I will have to think about what the *correct* behaviour is there – Marc Gravell Jul 05 '13 at 09:25
  • Well, I added a class with applyDefaultBehavior=true, and several subtypes. None of those types get created by the default factory, but classes that they reference do get created by the factory method if I remember correctly. I'll need to check again to be 100% sure. Btw. tnx for sharing your excellent work! – anakic Jul 09 '13 at 12:44