container icon indicating copy to clipboard operation
container copied to clipboard

Type mappings ignore InjectionMembers

Open ENikS opened this issue 6 years ago • 0 comments

InjectionMember parameters are ignored in mappings

Type mappings establish relations between implementation and registration types. For example, instances could be registered by base types or interfaces they implement.

Mappings could build their own pipelines or just map to some other types. In case when custom pipeline is required, injection members are used to specify how it should be created.

Always build registrations with InjectionMember parameters

When any injection members are associated with registration, the mapping should never redirect to other registrations, instead it should create its own pipeline and resolve using that pipeline.

To Reproduce

Note the non default InjectionConstructor in type registration:

[TestMethod]
public void Always_Build_If_Injected()
{
    var instance = new Service<object>();

    // Arrange
    Container.RegisterType(typeof(IService<>), typeof(Service<>), new InjectionConstructor(typeof(object)))
             .RegisterInstance(instance);
    // Act
    var value = Container.Resolve<IService<object>>();

    // Validate
    Assert.IsNotNull(value);
    // Should never be the same
    Assert.AreNotSame(instance, value);
}

ENikS avatar Aug 12 '20 23:08 ENikS