Can Dependency Injection be applied based on traits? #2047
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, it's possible. Try with First, build the Then, define the concrete implementation: https://github.com/caenguidanos/http-api-rs/blob/main/src/contexts/ecommerce/common/infrastructure/dependency_container.rs. Finally, inject |
Beta Was this translation helpful? Give feedback.
Yes, it's possible.
Try with
State
extractor to ensure correct type checking (it's recommendes from Axum docs).First, build the
Dyn<>
type: https://github.com/caenguidanos/http-api-rs/blob/main/src/contexts/ecommerce/backoffice/domain/product/repository.rs.Then, define the concrete implementation: https://github.com/caenguidanos/http-api-rs/blob/main/src/contexts/ecommerce/common/infrastructure/dependency_container.rs.
Finally, inject
with_state
on Router https://github.com/caenguidanos/http-api-rs/blob/main/src/contexts/ecommerce/backoffice/infrastructure/controller.rs and extract from handler https://github.com/caenguidanos/http-api-rs/blob/main/src/contexts/ecommerce/backoffice/infra…