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

For_Func_returned_type_with_lazy_dependency_Func_parameters_are_correctly_passed #394

Merged
merged 1 commit into from
Apr 21, 2021
Merged

Conversation

wgebczyk
Copy link
Contributor

Hi,

This quick fix attempts to fix mistake when processing lambda parameters and trying to take it from parent expression.
If there is assumption that ParamExprs.Length == ParamValues.Length, this change aligns code to the intention.

I've tried to make most simple unit test that is reusing as much as possible of existing types.

Another, standalone PoC of the issue can be found here:

public class Dep1 { }
public class Dep2 { }
public class Dep3 { }
public class Dep4 { }

public class Dep5
{
    public void Run() => Console.WriteLine("Dep5.Run()");
}

public class Dep6
{
    private readonly Lazy<Dep5> _dep5;

    public Dep6(Dep1 dep1, Dep2 dep2, Dep3 dep3, Dep4 dep4, Lazy<Dep5> dep5)
    {
        _dep5 = dep5;
    }

    public void Run()
    {
        Console.WriteLine("Dep6.Run() => Dep5.Run()");
        _dep5.Value.Run();
    }
}

static class Program
{
    static void Main()
    {
        var container = new Container();

        container.Register<Dep1>();
        container.Register<Dep2>();
        container.Register<Dep3>();
        container.Register<Dep4>();
        container.Register<Dep5>();
        container.Register<Dep6>();

        var funcDep6 = container.Resolve<Func<Dep1, Dep2, Dep6>>();
        var dep6 = funcDep6(new Dep1(), new Dep2());
        dep6.Run();
    }
}

@wgebczyk wgebczyk marked this pull request as ready for review April 20, 2021 14:32
@dadhi
Copy link
Owner

dadhi commented Apr 20, 2021

@wgebczyk Thank you, will look a bit later.

@dadhi dadhi added the bug Something isn't working label Apr 21, 2021
@dadhi dadhi assigned dadhi and wgebczyk and unassigned dadhi and wgebczyk Apr 21, 2021
@dadhi dadhi added this to the 4.7.6 milestone Apr 21, 2021
@dadhi
Copy link
Owner

dadhi commented Apr 21, 2021

@wgebczyk This is just an amazing pinpoint finding and the fix. Merging now.

@dadhi dadhi merged commit 6046dd6 into dadhi:master Apr 21, 2021
@dadhi
Copy link
Owner

dadhi commented Apr 21, 2021

@wgebczyk The version 4.7.6 with your fix is out.

@wgebczyk
Copy link
Contributor Author

That's amazing quick PR review, approval and releasing of the fix :D

Thank you!

@piotrandrzejewski1
Copy link

@dadhi Amazing job!

yallie pushed a commit to yallie/DryIoc that referenced this pull request Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants