Skip to content

Difference between ResolveAll and Enumerable.

Eugene Sadovoi edited this page Dec 17, 2018 · 5 revisions

ResolveAll

Historically Unity did not natively support resolving enumerable. It supported resolving arrays of dependencies but only if these where registered with name. Consider this example:

RegisterType(typeof(IService), typeof(Service));
RegisterType(typeof(IService), typeof(Service),  "Name-1");
RegisterType(typeof(IService), typeof(Service1), "Name-2");
RegisterType(typeof(IService), typeof(Service1), "Name-3");
RegisterType(typeof(IService), typeof(Service1), "Name-4");

When calling ResolveAll<IService> (Resolve<IService[]>) Unity would only return 4 items. These with 'Name-x'.

IEnumerable

Above behavior does not work in all the cases so support for IEnumerable<> has been added. As opposed to ResolveAll resolving Resolve<IEnumerable<SomeType>>() will return all registrations satisfying IServece. So in example above it will return all 5 objects.