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 { ... }
}
app
only.Expand description
Resource can be initialized in a standard way by Salak
.
Resource can be configured by
- Configuration properties by
Resource::Config
. - Customized by
Resource::Customizer
. - Other
Resource
s get byFactory
.
Associated Types
Configuration properties for current resource.
type Customizer
type Customizer
Customize current resource, usually by coding.
Required methods
fn create(
config: Self::Config,
factory: &FactoryContext<'_>,
customizer: impl FnOnce(&mut Self::Customizer, &Self::Config) -> Result<(), PropertyError>
) -> Result<Self, PropertyError>
fn create(
config: Self::Config,
factory: &FactoryContext<'_>,
customizer: impl FnOnce(&mut Self::Customizer, &Self::Config) -> Result<(), PropertyError>
) -> Result<Self, PropertyError>
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
fn post_initialized_and_registered(
_res: &Arc<Self>,
_factory: &FactoryContext<'_>
) -> Result<(), PropertyError>
fn post_initialized_and_registered(
_res: &Arc<Self>,
_factory: &FactoryContext<'_>
) -> Result<(), PropertyError>
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.
fn register_dependent_resources(
_: &mut FactoryBuilder<'_>
) -> Result<(), PropertyError>
fn register_dependent_resources(
_: &mut FactoryBuilder<'_>
) -> Result<(), PropertyError>
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.