reef icon indicating copy to clipboard operation
reef copied to clipboard

[REEF-2044] Serializing a List in Tang for C# has missing functionality

Open singlis opened this issue 6 years ago • 5 comments

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 #

singlis avatar Sep 12 '18 23:09 singlis

@jwang98052 - Hello Julia, would you be able to take a look? I believe this is an area you are familiar with. #WontFix

singlis avatar Sep 19 '18 20:09 singlis

@jwang98052 - have you had a chance to look at these changes? Thanks! #WontFix

singlis avatar Oct 03 '18 18:10 singlis

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)

singlis avatar Oct 19 '18 00:10 singlis

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.

markusweimer avatar Oct 19 '18 17:10 markusweimer

Sorry for late response. I will have a quick look today.

jwang98052 avatar Oct 19 '18 18:10 jwang98052