MichailShcherbakov / blackbox_di

Dependency injection for Rust
MIT License
1 stars 0 forks source link

Discovery mechanisms #1

Open wSedlacek opened 1 year ago

wSedlacek commented 1 year ago

I stumbled across this package looking for DI solutions for rust (coming from NestJS and Angular) and everything feels very familiar to those platforms which I quite enjoy however one thing that seems to be missing to create a solid decoupled web server is a way to discover controllers.

In NestJS you can use the ModuleContainer injectable to build services that introspect the injection tree and explore all provides to get the controllers or providers.

For example here: https://github.com/nestjs/nest/blob/5d5298219ee56a0b57d831d5e0009f7920d98ed0/packages/core/discovery/discovery-service.ts#L18C53-L18C53

This is also used for their CQRS and GraphQL solutions for attaching listeners on their command/query bus and building their graph respectively.

What could be used to introspect the tree in a similar manner with blackbox and rust? I am still very new to rust but can you check if some dynamic data type implements a certain trait to filter out providers when introspecting?

wSedlacek commented 1 year ago

Screenshot 2023-08-12 at 12 34 47

Looks like the core parts for this are here, I am just not knowledgable with rust yet to know how to deal with the Arc<dyn IInjecatlbe> that comes back from .get_instance()

Effectively I want to add meta data like #[get "/cats"] to methods in the impl and be able to reflect those back to build axtrics services for automatic registration.