How do I pass a parameter to the constructor using Light Inject?

前端 未结 4 1101
忘了有多久
忘了有多久 2021-01-01 11:41

Does Light Inject allow you to pass parameters to constructor when you resolve? I\'d like to know if both these frameworks do what Unity\'s ResolverOverride or DependencyOve

4条回答
  •  心在旅途
    2021-01-01 12:22

    In response to Liam's answer I would like to point out that there is a simpler way of doing this.

    If you have the following situation:

    public class Test : ITest
    {
       private IFoo _foo;
       public Test(IFoo foo, string parameter)
       {
          _foo = foo;
          ....
       }
    }
    

    You could write your ioc configuration as below

    _container.Register();
    _container.Register(
        () => new Test(
            _container.GetInstance(),
            "MyValue"
        )
    );
    

提交回复
热议问题