Skip to content

Unity IoC fails specification test in Microsoft.Extensions.DependencyInjection.Specification #1503

Closed

Description

@ENikS

Unity fails DisposesInReverseOrderOfCreation test

The test relies on FakeDisposableCallbackOuterService class to resolve an enumerable IEnumerable<IFakeMultipleService> and later verifies sequence of disposal against sequence of resolution.

Unity is using lazy resolution for the enumerable dependencies, meaning it does not resolve the dependency until the enumerable is actually requested by the iterator.

As you can see on this line the enumerable is never iterated. In other words, these IFakeMultipleService instances are never resolved.

As consequence, when disposed, these instances are not in the disposed list and so test fails.

Expected behavior

The test should not assume that IEnumerable already created these dependencies and instead should enumerate it into an array explicitly:

public FakeDisposableCallbackOuterServiceFixed(IFakeService singleService,
                                               IEnumerable<IFakeMultipleService> multipleServices,
                                               FakeDisposeCallback callback) : base(callback)
{
    SingleService = singleService;
    MultipleServices = multipleServices.ToArray();
}

Activity

  1. added this to the 3.0.0-preview6 milestone on Apr 23, 2019
  2. self-assigned this
    on Apr 23, 2019
  3. ghost locked as resolved and limited conversation to collaborators on Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions