Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property injection for type registered with DynamicParameters #652

Open
NikitaGrummo opened this issue Jun 14, 2023 · 0 comments
Open

Property injection for type registered with DynamicParameters #652

NikitaGrummo opened this issue Jun 14, 2023 · 0 comments

Comments

@NikitaGrummo
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant