[][src]Crate shaku

Shaku is a compile time dependency injection library. It can be used directly or through integration with application frameworks such as Rocket (see shaku_rocket).

Getting started

See the getting started guide

Crate features

By default shaku is thread-safe and exposes derive macros, but these can be disabled by opting out of the following features:

  • thread_safe: Requires components to be Send + Sync and provided services to be Send
  • derive: Uses the shaku_derive crate to provide proc-macro derives of Component and Provider.

Modules

guide

Getting started guide

Macros

module

Create a Module which is associated with some components and providers.

Structs

Container

Resolves services associated with a Module. A Container is built by a ContainerBuilder, or through the shortcut Container::default

ContainerBuilder

Builds a Container. Component parameters can be set, and both components and providers implementations can be overridden.

ModuleBuildContext

Builds a Module and its associated components. Build context, such as parameters and resolved components, are stored in this struct.

Traits

Component

Components provide a service by implementing an interface. They may use other components as dependencies.

HasComponent

Indicates that a module contains a component which implements the interface.

HasProvider

Indicates that a module contains a provider which implements the interface.

HasSubmodule

Indicates that a module contains a submodule.

Interface

Interfaces must be 'static in order to be stored in the container (hence the Any requirement).

Module

A module represents a group of services. By implementing traits such as HasComponent on a module, service dependencies are checked at compile time. At runtime, modules hold the components they are associated with.

ProvidedInterface

Provided interfaces must be 'static in order for the provider to be stored in the container (hence the Any requirement).

Provider

Like Components, providers provide a service by implementing an interface.

Type Definitions

ProviderFn

The type signature of Provider::provide. This is used when overriding a provider via ContainerBuilder::with_provider_override

Derive Macros

Component
Provider