Skip to main content

LifecycleContext

Struct LifecycleContext 

Source
pub struct LifecycleContext<'a, A, R, P>
where A: AggregateRoot, R: Repository<Aggregate = A>, P: DomainEventPublisher<Event = <A as AggregateRoot>::Event>,
{ /* private fields */ }
Expand description

English:
Coordinates one synchronous aggregate save and event dispatch sequence.

日本語:
同期の集約保存とイベント配信を一連で調整します。

Implementations§

Source§

impl<'a, A, R, P> LifecycleContext<'a, A, R, P>
where A: AggregateRoot, R: Repository<Aggregate = A>, P: DomainEventPublisher<Event = <A as AggregateRoot>::Event>,

Source

pub fn new( aggregate: &'a mut A, repository: &'a mut R, publisher: &'a mut P, ) -> LifecycleContext<'a, A, R, P>

English:
Creates a lifecycle context borrowing the aggregate, repository, and publisher mutably.

日本語:
集約、リポジトリ、パブリッシャーを可変借用するライフサイクルコンテキストを作成します。

Examples found in repository?
examples/cqrs.rs (line 97)
85    fn handle<F>(&mut self, id: &u64, amount: u32, callback: F) -> Result<(), Error>
86    where
87        F: for<'a> LifecycleCallback<'a, Order, Store, Publisher, Output = (), Error = Error>,
88    {
89        let mut order = self.store.find_by_id(id).unwrap().ok_or(Error::NotFound)?;
90        if !Positive.is_satisfied_by(&amount).unwrap() {
91            return Err(Error::Rejected);
92        }
93        let total = order.total.checked_add(amount).ok_or(Error::Rejected)?;
94        Limit.check(&total)?;
95        order.total = total;
96        order.record_event(Placed(order.id));
97        let mut context = LifecycleContext::new(&mut order, &mut self.store, &mut self.publisher);
98        callback.call(&mut context)?;
99        context.complete()?;
100        Ok(())
101    }
Source

pub fn save( &mut self, ) -> Result<(), LifecycleOperationError<<R as Repository>::Error>>

English:
Attempts repository persistence once; adapter errors are returned and the attempt cannot be retried.

日本語:
リポジトリへの保存を一度試行します。アダプターエラーを返し、再試行はできません。

Examples found in repository?
examples/cqrs.rs (line 116)
109    fn call<'callback>(
110        self,
111        context: &'callback mut LifecycleContext<'storage, Order, Store, Publisher>,
112    ) -> Result<(), Error>
113    where
114        'storage: 'callback,
115    {
116        context.save()?;
117        context.dispatch()?;
118        Ok(())
119    }
Source

pub fn dispatch( &mut self, ) -> Result<(), LifecycleOperationError<<P as DomainEventPublisher>::Error>>

English:
Attempts event dispatch once; adapter errors are returned and the attempt cannot be retried.

日本語:
イベント配信を一度試行します。アダプターエラーを返し、再試行はできません。

Examples found in repository?
examples/cqrs.rs (line 117)
109    fn call<'callback>(
110        self,
111        context: &'callback mut LifecycleContext<'storage, Order, Store, Publisher>,
112    ) -> Result<(), Error>
113    where
114        'storage: 'callback,
115    {
116        context.save()?;
117        context.dispatch()?;
118        Ok(())
119    }
Source

pub fn complete(self) -> Result<(), LifecycleCompletionError>

English:
Consumes the context and succeeds only when both save and dispatch succeeded.

日本語:
コンテキストを消費し、保存と配信の両方が成功した場合にのみ成功します。

Examples found in repository?
examples/cqrs.rs (line 99)
85    fn handle<F>(&mut self, id: &u64, amount: u32, callback: F) -> Result<(), Error>
86    where
87        F: for<'a> LifecycleCallback<'a, Order, Store, Publisher, Output = (), Error = Error>,
88    {
89        let mut order = self.store.find_by_id(id).unwrap().ok_or(Error::NotFound)?;
90        if !Positive.is_satisfied_by(&amount).unwrap() {
91            return Err(Error::Rejected);
92        }
93        let total = order.total.checked_add(amount).ok_or(Error::Rejected)?;
94        Limit.check(&total)?;
95        order.total = total;
96        order.record_event(Placed(order.id));
97        let mut context = LifecycleContext::new(&mut order, &mut self.store, &mut self.publisher);
98        callback.call(&mut context)?;
99        context.complete()?;
100        Ok(())
101    }

Auto Trait Implementations§

§

impl<'a, A, R, P> !UnwindSafe for LifecycleContext<'a, A, R, P>

§

impl<'a, A, R, P> Freeze for LifecycleContext<'a, A, R, P>

§

impl<'a, A, R, P> RefUnwindSafe for LifecycleContext<'a, A, R, P>

§

impl<'a, A, R, P> Send for LifecycleContext<'a, A, R, P>

§

impl<'a, A, R, P> Sync for LifecycleContext<'a, A, R, P>

§

impl<'a, A, R, P> Unpin for LifecycleContext<'a, A, R, P>

§

impl<'a, A, R, P> UnsafeUnpin for LifecycleContext<'a, A, R, P>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.