Hi, I'm looking for ideas on how to structure a fairly complex system of components/services/boundaries of logic.
As a minimal case let's say I want to control time, so I have a bunch of logic to do with setting time, getting time, and calculating how much time has elapsed. So a user can jump forward in time for example.
I have another set of bunches of logic to do with sending out email reports, sending HTML to the client, maintenance, auditing etc.
In Java land I would have an interface for each bit of logic, maybe one called
IControlTime {
DateTime getTime();
}
then I might have a
class ReportOne {
@MagicAnnotation
private final IControlTime clock;
// ...
}
class ReportTwo {
@MagicAnnotation
private final IControlTime clock;
// ...
}
and so on.
In Rust, I could naively repeat exactly this using traits (and Boxes to share them, or Arc, RwLocks as I'm using Tokio), but it doesn't particularly feel very ergonomic doing this, particularly when they are most likely going to be hundreds of these components.
I've seen a few dependency injection crates, but something is holding me back from going down that route too.
Is the "idiomatic" (whatever that means ;-)) approach to really just instantiate them one by one and wire them up manually?
I don't really know what I'm looking for other than confidence that I'm not walking a weird and lonely path - what do you all do here?