Crate runtime_injector_actix[][src]

Utility library for injecting dependencies into actix-web applications.

Modules

docs

Additional documentation modules.

Macros

define_module

Defines a new module using a domain specific language.

interface

Marks a trait as being an interface for many other types. This means that a request for the given trait can resolve to any of the types indicated by this macro invocation.

Structs

ConstantProvider

A provider which returns a constant, predetermined value. Note that this is technically a singleton service in that it does not recreate the value each time it is requested.

FallibleServiceFactory

A service factory that may fail during service creation with a custom error type. During activation failure, an instance of InjectError::ActivationFailed is returned as an error.

Injected

An injected request. Any request to the Injector can be injected by wrapping it in this type and providing it as a parameter to your request handler.

Injector

A runtime dependency injection container. This holds all the bindings between service types and their providers, as well as all the mappings from interfaces to their implementations (if they differ).

InjectorBuilder

A builder for an Injector.

InterfaceProvider

Provides a service as an implementation of an interface. See TypedProvider::with_interface() for more information.

Module

A collection of providers that can be added all at once to an InjectorBuilder. Modules can be used to group together related services and configure the injector in pieces rather than all at once.

OwnedServicesIter

An iterator over all the implementations of an interface. Each service is activated on demand.

RequestInfo

Information about an active request.

ServiceInfo

Type information about a service.

Services

A collection of all the providers for a particular interface.

ServicesIter

An iterator over all the implementations of an interface. Each service is activated on demand.

SingletonProvider

A service provider that only creates a single instance of the service. The service is created only during its first request. Any subsequent requests return service pointers to the same service.

TransientProvider

A service provider that creates an instance of the service each time it is requested. This will never return two service pointers to the same instance of a service.

Enums

InjectError

An error that has occurred during creation of a service.

Traits

AsAny

Defines a conversion for a type into a dyn Any trait object.

Interface

Indicates that a type can resolve services. The most basic implementation of this trait is that each sized service type can resolve itself. This is done by requesting the exact implementation of itself from the injector. However, the injector cannot provide exact implementations for dynamic types (dyn Trait). For this reason, any interfaces using traits must be declared explicitly before use. This trait should usually be implemented by the interface! macro.

InterfaceFor

Marker trait that indicates that a type is an interface for another type. Each sized type is an interface for itself, and each dyn Trait is an interface for the types that it can resolve. This trait should usually be implemented by the interface! macro, and is strictly used to enforce stronger type checking when assigning implementations for interfaces.

IntoFallible

Defines a conversion into a fallible service factory. This trait is automatically implemented for all service factories that return a Result<T, E> with a type that implements Error + Service.

IntoSingleton

Defines a conversion into a singleton provider. This trait is automatically implemented for all service factories.

IntoTransient

Defines a conversion into a transient provider. This trait is automatically implemented for all service factories.

Provider

Weakly typed service provider. Given an injector, this will provide an implementation of a service. This is automatically implemented for all types that implement TypedProvider, and TypedProvider should be preferred if possible to allow for stronger type checking.

Request

A request to an injector.

RequestParameter

A parameter for configuring requested services.

Service

Implemented automatically on types that are capable of being a service.

ServiceFactory

A factory for creating instances of a service. All functions of arity 12 or less are automatically service factories if the arguments to that function are valid service requests and the return value is a valid service type.

TypedProvider

A strongly-typed service provider. Types which implement this provide instances of a service type when requested. Examples of typed providers include providers created from service factories or constant providers. This should be preferred over Provider for custom service providers if possible due to the strong type guarantees this provides. Provider is automatically implemented for all types which implement TypedProvider.

Functions

constant

Create a provider from a constant value. While the service itself will never be exposed through a mutable reference, if it supports interior mutability, its fields still can be mutated. Since the provider created with this function doesn’t recreate the value each time it’s requested, state can be stored in this manner.

Type Definitions

DynSvc

A reference-counted service pointer holding an instance of dyn Any.

InjectResult

A result from attempting to inject dependencies into a service and construct an instance of it.

OwnedDynSvc

An owned service pointer holding an instance of dyn Any.

Svc

A reference-counted pointer holding a service. The pointer type is determined by the feature flags passed to this crate.