Releases: unitycontainer/unity
5.8.7.517
Fixed Issues
#55 - Added support for Net Core 2.0
#57 - Override loading optimization during resolve
#87 - Fixed enumerable resolution with regard to generic constraints
#88 - Fixed edge case where hierarchical containers resolve with overrides
#92 - Fixed array resolution with regard to generic constraints
#94 - Minor optimization during resolution
#95 - Fixed bug related to resolving registered array
#96 - Fixed bug related to resolving registered enumerable
#233 - PDB Causing TFS Build to "Partially Succeed"
5.8.6.508
5.8.5.506
5.8.4.502
5.8.3.499
5.8.2.496
5.8.1.490
5.8.0.488
This release
This release fixes #72 issue.
Problem
Unity has build in support for IEnumerable, Array, and Lazy. Theoretically it should be able to distinguish these types and properly resolve them individually and in combination. Unfortunately it did not do so.
container.Resolve<Lazy<IEnumenrable<type>>> - will resolve correctly
container.Resolve<IEnumenrable<Lazy<type>>> - will resolve empty
Fix
This release fixes resolution of collections of generic and array types and Lazy collections of items. This will now work fine:
Resolve<Lazy<IEnumenrable<type>>>
Resolve<IEnumenrable<Lazy<type>>>
Resolve<Lazy<type[]>>
Resolve<Lazy<type>[]>
Resolve<IEnumerable<Lazy<Func<IService>>>>()
Resolve<IEnumerable<Func<Lazy<IService>>>>()
Resolve<Lazy<Func<IService>>[]>()
Resolve<Func<Lazy<IService>>[]>()
The logic behind resolving collections is to find enumerable type and get all registrations for it no matter how deep in generics tree. Enumerated type could be:
- Non generic (Constructed Generic) type
- Explicitly registered with container type
So, in this example
RegisterType<IService, Service>("1", new ContainerControlledLifetimeManager());
RegisterType<IService, Service>("2", new ContainerControlledLifetimeManager());
RegisterType<IService, Service>("3", new ContainerControlledLifetimeManager());
RegisterType<IService, Service>();
Resolve<IEnumerable<Func<Lazy<IService>>>>();
enumerable will return four instances of method which returns Lazy<IService>
. But in this example:
RegisterType<IService, Service>("1", new ContainerControlledLifetimeManager());
RegisterType<IService, Service>("2", new ContainerControlledLifetimeManager());
RegisterType<IService, Service>("3", new ContainerControlledLifetimeManager());
RegisterType<IService, Service>();
RegisterInstance(new Lazy<IService>(() => new Service())); <-- note this registraton
Resolve<IEnumerable<Func<Lazy<IService>>>>();
Enumerable will return only one item.