Trait salak::Factory[][src]

pub trait Factory: Environment {
    fn get_resource_by_namespace<R: Resource + Send + Sync + Any>(
        &self,
        namespace: &'static str
    ) -> Result<Arc<R>, PropertyError>;
fn init_resource_with_builder<R: Resource>(
        &self,
        builder: ResourceBuilder<R>
    ) -> Result<R, PropertyError>;
fn run(&mut self) -> Result<(), PropertyError>; fn get_resource<R: Resource + Send + Sync + Any>(
        &self
    ) -> Result<Arc<R>, PropertyError> { ... }
fn init_resource<R: Resource>(&self) -> Result<R, PropertyError> { ... }
fn get_service<S: Service>(&self) -> Result<S, PropertyError> { ... } }
This is supported on crate feature app only.
Expand description

Factory is a resource manager. It provides a group of functions to manage resource and their dependencies. Users may use factory to package all components of one logic unit, such as redis client configuration resource, together.

In a production ready redis client configuration, we may need configuration to specify redis host, port, etc, and we also need to set some callbacks for monitoring the client. So we can make the redis client configuration as resource, it will register redis client resource, redis monitor resource, and other relative resources.

  • In redis client resource, it needs expose configuration for users to specify basic parameters for initializing redis client.

  • In redis monitor resource, it may need other common resource such as how to send metrics. So it’s responsibility is collecting the redis metrics and use common metric resource to send the metrics.

  • And other resources may be added in the redis client configuration.

Users may register redis client configuration resource to initializing all of these resources. By using namespace, users can easily create multiple group instances of same type resource.

Required methods

Get resource Arc<R> from cache by namespace. Users can customize the resource by SalakBuilder::register_resource().

Initialize Resource with builder.

Run the resource.

Provided methods

Get resource Arc<R> from cache with default namespace. Users can customize the resource by SalakBuilder::register_resource().

Initialize Resource.

Get service.

Implementors