reef
reef copied to clipboard
[REEF-2044] Serializing a List in Tang for C# has missing functionality
The current state did not handle serializing out a list when a list was set in the configuration. This now adds that functionality along with unit tests.
JIRA: REEF-2044
Closes #
@jwang98052 - Hello Julia, would you be able to take a look? I believe this is an area you are familiar with. #WontFix
@jwang98052 - have you had a chance to look at these changes? Thanks! #WontFix
Thanks for the feedback @markusweimer. I have posted an update. Although there is one issue that bothers me with lists which is no code seems to serialize a list of classes, it looks to always be a string.
Is serializing out a list of classes that can be injected supposed to work?
I started to make changes to this to see what it would take. First I had to modify this signature:
ICsConfigurationBuilder BindList<U, V, T>(GenericType<U> iface, IList<GenericType<V>> impl)
to
ICsConfigurationBuilder BindList<U, V, T>(GenericType<U> iface, IList<V> impl)
Then I added a test similar to what is done with Sets:
ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder();
var t = new System.Collections.Generic.List<Integer1>();
t.Add(new Integer1(2));
t.Add(new Integer1(3));
cb.BindList<ListOfClasses, Integer1, INumber>(GenericType<ListOfClasses>.Class, t)
IInjector i = TangFactory.GetTang().NewInjector(cb.Build());
IList<INumber> actual = i.GetInstance<PoolList>().Numbers;
The error is on the last line when we try to call GetInstance to construct the object. It looks like it has to do with resolving the parameters (2,3) to pass to the class on construction. Note PoolList is a class that has an inject constructor. It takes in IList<INumber> as the parameter, it has a property called Numbers that returns an IList of INumbers:
[Inject]
private PoolList([Parameter(typeof(ListOfClasses))] IList<INumber> numbers)
Is serializing out a list of classes that can be injected supposed to work?
I don't think so. Tang enforces singleton semantics for objects to be instantiated by it. And in a List, one can refer to the same type multiple times, without giving it a name as in NamedParameter
. Hence, I believe it is expected behavior for this to only ever work with Sets.
Sorry for late response. I will have a quick look today.