coi-rocket
Dependency Injection in Rust
This crate provides integration support between coi
and rocket
. It
exposes an inject
procedural attribute macro to generate the code for
retrieving your dependencies from a Container
registered with rocket
.
Example
// What's needed for the example fn below
use get;
use Json;
use Arc;
// Add the `inject` attribute to the function you want to inject
// What this crate provides
// Just data models for the above fn
use Serialize;
// An example of what's usually needed to make effective use of this
// crate is below
use Inject;
// This section shows coi being put to use
// It's very important that the version of coi and the version
// of coi-rocket used match since coi-rocket implements
// some coi traits
// Here we're marking a trait as injectable
// And here we're marking a type that's capable of providing the
// above trait
// Normal impl for struct
// Normal impl of trait for struct
// The data that will be passed between services
// Here's the trait from above
// And it's setup below
;
See the repo coi-rocket-sample
for a more involved example.
License
SPDX-License-Identifier: MIT OR Apache-2.0