Skip to content

Property injection for type registered with DynamicParameters #652

@NikitaGrummo

Description

@NikitaGrummo

Hi,
We want to have types registered with DynamicParameters and then be injected as properties. Simple example below, in case 2 and 3 class2 variable has Prop = null. Case 2 is preferable for us, we need access to container on type creation. Could you please suggest workaround or fix such behavior if there is a bug. Thanks in advance

public class Class1
{
    private readonly int _intDep;

    public Class1(int intDep)
    {
        _intDep = intDep;
    }
}

public class Class2
{
    public Class1 Prop { get; set; }
}
var container = new WindsorContainer();

container.Register(Component.For<Class1>()
    .DependsOn(Dependency.OnValue("intDep", 1)) //case 1
    //.DynamicParameters((kernel, args) => args["intDep"] = 1) //case 2
    //.DependsOn((kernel, args) => args["intDep"] = 1) //case 3
    .LifestyleTransient());
container.Register(Component.For<Class2>().LifestyleTransient());

var class1 = container.Resolve<Class1>(); //ok - integer injected for all cases
var class2 = container.Resolve<Class2>(); //null Prop for case 2 and 3

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