Skip to main content

ApplicationContextBuilder

Struct ApplicationContextBuilder 

Source
pub struct ApplicationContextBuilder { /* private fields */ }
Expand description

Application context builder

ApplicationContextBuilder provides a fluent API for constructing an ApplicationContext with various configuration sources, profiles, and settings.

§Examples

use verdure_context::ApplicationContextBuilder;

let context = ApplicationContextBuilder::new()
    .with_property("app.name", "MyApp")
    .build()
    .unwrap();

Implementations§

Source§

impl ApplicationContextBuilder

Source

pub fn new() -> Self

Creates a new application context builder

§Examples
use verdure_context::ApplicationContextBuilder;

let builder = ApplicationContextBuilder::new();
Source

pub fn with_config_source(self, source: ConfigSource) -> Self

Adds a configuration source

§Arguments
  • source - The configuration source to add
§Examples
use verdure_context::{ApplicationContextBuilder, ConfigSource};
use std::collections::HashMap;

let builder = ApplicationContextBuilder::new()
    .with_config_source(ConfigSource::Environment);
Source

pub fn with_toml_config_file<P: AsRef<Path>>(self, path: P) -> Self

Loads configuration from a TOML file

§Arguments
  • path - Path to the TOML configuration file
§Examples
use verdure_context::ApplicationContextBuilder;

let builder = ApplicationContextBuilder::new()
    .with_toml_config_file("config/app.toml");
Source

pub fn with_yaml_config_file<P: AsRef<Path>>(self, path: P) -> Self

Loads configuration from a YAML file

§Arguments
  • path - Path to the YAML configuration file
§Examples
use verdure_context::ApplicationContextBuilder;

let builder = ApplicationContextBuilder::new()
    .with_yaml_config_file("config/app.yaml");
Source

pub fn with_properties_config_file<P: AsRef<Path>>(self, path: P) -> Self

Loads configuration from a Properties file

§Arguments
  • path - Path to the Properties configuration file
§Examples
use verdure_context::ApplicationContextBuilder;

let builder = ApplicationContextBuilder::new()
    .with_properties_config_file("config/app.properties");
Source

pub fn with_config_file<P: AsRef<Path>>(self, path: P) -> Self

Loads configuration from a file with automatic format detection

The format is detected based on the file extension:

  • .toml -> TOML format
  • .yaml or .yml -> YAML format
  • .properties -> Properties format
  • Others -> Attempts to parse as TOML first, then YAML, then Properties
§Arguments
  • path - Path to the configuration file
§Examples
use verdure_context::ApplicationContextBuilder;

let builder = ApplicationContextBuilder::new()
    .with_config_file("config/app.yaml")
    .with_config_file("config/database.properties")
    .with_config_file("config/server.toml");
Source

pub fn with_property( self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Sets a property value

§Arguments
  • key - The property key
  • value - The property value
§Examples
use verdure_context::ApplicationContextBuilder;

let builder = ApplicationContextBuilder::new()
    .with_property("app.name", "MyApplication");
Source

pub fn build(self) -> ContextResult<ApplicationContext>

Builds the application context

§Returns

A new ApplicationContext instance configured with the specified settings

§Errors

Returns an error if context initialization fails

§Examples
use verdure_context::ApplicationContextBuilder;

let context = ApplicationContextBuilder::new()
    .with_property("app.name", "MyApp")
    .build()
    .unwrap();

Trait Implementations§

Source§

impl Debug for ApplicationContextBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ApplicationContextBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.