YairHalberstadt / stronginject

compile time dependency injection for .NET
MIT License
845 stars 24 forks source link

Confusing use of the term 'delegate parameters' in the readme #190

Closed jnm2 closed 2 years ago

jnm2 commented 2 years ago

https://github.com/YairHalberstadt/stronginject#decorators:

Instances provided by delegate parameters are never decorated.

If I understand what it's saying, I'm relieved that it's incorrect. It would be a very unpleasant pit of failure to switch from injecting B to Func<B> and start getting a different instance.

Demonstrating (using 1.4.4) an instance provided by a delegate parameter being decorated:

using System;
using StrongInject;

using var container = new Container();

container.Run(a =>
{
    a.FuncOfB(); // Prints: Decorated B!
});

[Register(typeof(A)), Register(typeof(B))]
partial class Container : IContainer<A>
{
    [DecoratorFactory]
    private static B Test(B b)
    {
        Console.WriteLine("Decorated B!");
        return b;
    }
}

record A(Func<B> FuncOfB);
record B;
YairHalberstadt commented 2 years ago

That's a delegate return type, not a delegate parameter...

jnm2 commented 2 years ago

Ah, I got it now from chatting on Discord. I'm thinking of something like "When an injected delegate is invoked with arguments, the arguments to the delegate ("going in") are not decorated. The return value from the delegate ("coming out") is decorated." And maybe an example.

Maybe I'll review for other occurrences of 'delegate parameter' since it can be understood as "a delegate-typed parameter" as well as "a parameter of a delegate."