Skip to main content

Injectable

Trait Injectable 

Source
pub trait Injectable:
    Send
    + Sync
    + 'static {
    // Required method
    fn construct(registry: &ProviderRegistry) -> Arc<Self>;

    // Provided methods
    fn scope() -> ProviderScope { ... }
    fn on_module_init<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_module_destroy<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_application_bootstrap<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn on_application_shutdown<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

Application service or provider type constructed through the DI container.

construct is synchronous. Perform async I/O in Self::on_module_init or after you have an Arc<Self> from the registry. Lifecycle hooks run for singleton providers when the framework drives ProviderRegistry::run_on_module_init and related methods (see NestFactory / listen).

Scopes: override Self::scope via #[injectable(scope = "...")].

Docs: mdBook Fundamentals (docs/src/fundamentals.md).

Required Methods§

Source

fn construct(registry: &ProviderRegistry) -> Arc<Self>

Provided Methods§

Source

fn scope() -> ProviderScope

Provider scope used when the module registers this type.

Source

fn on_module_init<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn on_module_destroy<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn on_application_bootstrap<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn on_application_shutdown<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<O, M> Injectable for ModuleOptions<O, M>
where O: Send + Sync + 'static, M: 'static,