Skip to content

Runtime Decorators Not Applied to Instanciated Classes #672

@blalonde

Description

@blalonde

Don't know if this is by design or not.

private interface IInterface
{
	
}

private class Decorator : IInterface
{
	public Decorator(IInterface i)
	{

	}
}

private class Instance : IInterface
{
	
}

[Test]
public void When_Then_()
{
	var container = new Container(x => x.For<IInterface>().Use<Instance>());
	var i1 = container.GetInstance<IInterface>();

	container.Configure(x => x.For<IInterface>().DecorateAllWith<Decorator>());
	var i2 = container.GetInstance<IInterface>();

	i2.Should().BeOfType<Decorator>();
}

Commenting out i1 instanciation works.

My feeling is DecorateAllWith should be applied when changing the runtime configuration even if a previous IInterface was instanciated without a decorator.

Workaround : Copy the x => x.For().Use() in the runtime configuration too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions