Skip to content

InjectionFactory and RegisterFactory doesn't work for open generic types #145

@hypercodeplace

Description

@hypercodeplace

Description

InjectionFactory and .RegisterFactory don't work for open generic types. Resolves fail with an exception "Unity.ResolutionFailedException : The current type is an interface and cannot be constructed. Are you missing a type mapping?"

To Reproduce

Test to reproduce it:

public interface IFoo<T> { }
public class Foo<T> : IFoo<T> { }

public class Tests
{
    [TestMethod]
    public void InjectionFactoryMustWorkForOpenGenericTypes()
    {
        var container = new UnityContainer()
            .RegisterType(typeof(IFoo<>), new InjectionFactory(c => new Foo<object>()));

        container.Resolve(typeof(IFoo<object>));
    }

    [Test]
    public void RegisterFactoryMustWorkForOpenGenericTypes()
    {
        var container = new UnityContainer()
            .RegisterFactory(typeof(IFoo<>), c => new Foo<object>());

        container.Resolve(typeof(IFoo<object>));
    }
}

Additional context

There was no problem with 5.8.13 (for same code for InjectionFactory), but is in 5.9.7. Looks like the issue is connected with unitycontainer/abstractions#89.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions