platform icon indicating copy to clipboard operation
platform copied to clipboard

Use `app()->makeWith()` to creating new class instance.

Open liaosankai opened this issue 2 years ago • 0 comments

How about replace "new Metric($labels);" with "app()->makeWith(Metric::class, ['labels' => $labels]);"

By using the app()->makeWith() method, we can dynamically resolve dependent objects through the Service Container while providing the necessary parameters. This approach adheres better to the Dependency Inversion Principle and the Single Responsibility Principle, offering greater flexibility for future expansions and testing.

liaosankai avatar May 22 '23 14:05 liaosankai