Trait salak::Resource[][src]

pub trait Resource: Sized {
    type Config: PrefixedFromEnvironment;
    type Customizer;
    fn create(
        config: Self::Config,
        factory: &FactoryContext<'_>,
        customizer: impl FnOnce(&mut Self::Customizer, &Self::Config) -> Result<(), PropertyError>
    ) -> Result<Self, PropertyError>; fn post_initialized_and_registered(
        _res: &Arc<Self>,
        _factory: &FactoryContext<'_>
    ) -> Result<(), PropertyError> { ... }
fn register_dependent_resources(
        _: &mut FactoryBuilder<'_>
    ) -> Result<(), PropertyError> { ... }
fn order() -> Ordered { ... } }
This is supported on crate feature app only.
Expand description

Resource can be initialized in a standard way by Salak.

Resource can be configured by

Associated Types

Configuration properties for current resource.

Customize current resource, usually by coding.

Required methods

Create resource, all initialization is implemented at this function. Use proper config, leave users to customizing current resource, and also request for other resources.

Provided methods

Action after initialized and registered to registry. Factory::init_resource() and Factory::init_resource_with_builder() will not call this function, because they don’t register resource to registry.

Register dependent resources. Create resource will only request for other resources, if the resource is not registered yet by SalakBuilder::register_resource, an error will occure during the creating process. You may either register the resource using this function or leave the user to register.

The guideline of where to register resource is to find out the boundary of resources. If you developing a service, and it depends some database resources, then you should leave the user to register database resource. If you are developing a database resource, and you need some other resources that used only by this database resource, you should treat them as a whole logical resource, and the database resource has responsibility for registering the dependent resources.

Order of initializing priority.

Implementations on Foreign Types

Implementors