Skip to content

[Feature Request] Ability to use dependencies in Assemblers #1

@bertoost

Description

@bertoost

Hi there,

First of all; great package!! We're overthinking to replace our own implementation by your package.

Therefore;
We'd like to use a dependency injection and loop over all mapped DTO's to compose objects further.

Would be nice to do this directly from the assembler, since this is still about composing the DTO objects. An example below;

class ExmapleAssembler extends ArgonautAssembler
{
    public function __construct(
        private readonly ExampleStrategy $strategy,
    ) {
    }

    public function toExmpleDto(object $input): ExmpleDto
    {
        $dto = new ExampleDto([
            // ...
        ]);

        $this->strategy->doSomething($dto);

        return $dto;
    }
}

The only change is non-static to methods. But of course this will have effect on the fromArray() and fromCollection() as well.

When it's not static, you can also inject the assembler itself into a service or something too.

Like to hear from you again.

Regards, Bert

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationenhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions