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

Support for composite decorators #265

Open
Simble opened this issue Nov 16, 2020 · 5 comments
Open

Support for composite decorators #265

Simble opened this issue Nov 16, 2020 · 5 comments
Labels
question Further information is requested

Comments

@Simble
Copy link

Simble commented Nov 16, 2020

Does and/or will Lamar have support for composite decorators? Like StructureMap.

If not, is there an alternative approach to achieving the same result?

@jeremydmiller jeremydmiller added the question Further information is requested label Nov 19, 2020
@jeremydmiller
Copy link
Member

@Simble You should be able to do that now. You do just mean wrapping decorators in decorators, right? That should work out of the box, but I'll admit that I never thought to try that.

@Simble
Copy link
Author

Simble commented Nov 19, 2020

Hi @jeremydmiller, thank you for getting back to me.

By composite (decorator) pattern I meant a situation as described in the code below.
You have multiple classes that implement an interface, you register all the implementations as a IEnumerable and those are injected into another implementation of that interface, that can "compositely" perform an action on all of them:

public interface ISomething
{
    IEnumerable<string> GetNames();
}

public class One : ISomething
{
    public IEnumerable<string> GetNames() => new[] { "one" };
}

public class Two : ISomething
{
    public IEnumerable<string> GetNames() => new[] { "two" };
}

public class SomethingComposite : ISomething
{
    private readonly IEnumerable<ISomething> _others;

    public SomethingComposite(IEnumerable<ISomething> others)
    {
        _others = others;
    }

    public IEnumerable<string> GetNames() => _others.SelectMany(other => other.GetNames());
}

Is it possible to achieve this? I really like Lamar and use this pattern a lot, to adhere to the single responsibility principle.

@jeremydmiller
Copy link
Member

"I think so" or " I dont' know why that wouldn't work" is the answer

@Simble
Copy link
Author

Simble commented Nov 19, 2020

Unfortunately I am getting a bi-directional exception.

@jeremydmiller
Copy link
Member

Do you have repro steps?

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

No branches or pull requests

2 participants