pub struct ServiceContainer { /* private fields */ }Expand description
Service container that holds all repository instances and provides factory methods for use cases.
The container uses Arc for thread-safe sharing of repository instances across use cases.
All repositories are stored as trait objects, allowing for easy substitution with mock
implementations during testing.
§Design Principles
- Singleton Repositories: Repository instances are created once and shared across all use cases
- Factory Methods: Use cases are created on-demand with their dependencies injected
- Thread Safety: All repositories are wrapped in
Arcfor concurrent access - Testability: Repositories can be swapped with mocks via the builder
§Stateless Use Cases
Some use cases are stateless (unit structs with static methods). These are NOT included in the container and should be used directly:
PublishArticleUseCase::execute(article)ArchiveArticleUseCase::execute(article)DeleteArticleUseCase::execute(article)RestoreArticleUseCase::execute(article)RecordArticlePurchaseUseCase::execute(article, amount)ExtendAccessUseCase::execute(token, days)- And others…
§Example
let container = ContainerBuilder::new()
.with_in_memory_repositories()
.build();
// Get use cases with dependencies injected
let register_creator = container.register_creator_use_case();
let initiate_payment = container.initiate_payment_use_case();Implementations§
Source§impl ServiceContainer
impl ServiceContainer
Sourcepub fn new(
creator_repository: Arc<dyn CreatorRepository>,
article_repository: Arc<dyn ArticleRepository>,
transaction_repository: Arc<dyn TransactionRepository>,
access_token_repository: Arc<dyn AccessTokenRepository>,
fork_repository: Arc<dyn ForkRepository>,
event_stream_repository: Arc<dyn EventStreamRepository>,
) -> Self
pub fn new( creator_repository: Arc<dyn CreatorRepository>, article_repository: Arc<dyn ArticleRepository>, transaction_repository: Arc<dyn TransactionRepository>, access_token_repository: Arc<dyn AccessTokenRepository>, fork_repository: Arc<dyn ForkRepository>, event_stream_repository: Arc<dyn EventStreamRepository>, ) -> Self
Creates a new service container with the provided repositories.
Prefer using ContainerBuilder for a more fluent API.
Sourcepub fn creator_repository(&self) -> Arc<dyn CreatorRepository>
pub fn creator_repository(&self) -> Arc<dyn CreatorRepository>
Returns the creator repository instance.
Sourcepub fn article_repository(&self) -> Arc<dyn ArticleRepository>
pub fn article_repository(&self) -> Arc<dyn ArticleRepository>
Returns the article repository instance.
Sourcepub fn transaction_repository(&self) -> Arc<dyn TransactionRepository>
pub fn transaction_repository(&self) -> Arc<dyn TransactionRepository>
Returns the transaction repository instance.
Sourcepub fn access_token_repository(&self) -> Arc<dyn AccessTokenRepository>
pub fn access_token_repository(&self) -> Arc<dyn AccessTokenRepository>
Returns the access token repository instance.
Sourcepub fn fork_repository(&self) -> Arc<dyn ForkRepository>
pub fn fork_repository(&self) -> Arc<dyn ForkRepository>
Returns the fork repository instance.
Sourcepub fn event_stream_repository(&self) -> Arc<dyn EventStreamRepository>
pub fn event_stream_repository(&self) -> Arc<dyn EventStreamRepository>
Returns the event stream repository instance.
Sourcepub fn register_creator_use_case(&self) -> RegisterCreatorUseCase
pub fn register_creator_use_case(&self) -> RegisterCreatorUseCase
Creates a new RegisterCreatorUseCase with injected dependencies.
Sourcepub fn update_creator_use_case(&self) -> UpdateCreatorUseCase
pub fn update_creator_use_case(&self) -> UpdateCreatorUseCase
Creates a new UpdateCreatorUseCase with injected dependencies.
Sourcepub fn create_article_use_case(&self) -> CreateArticleUseCase
pub fn create_article_use_case(&self) -> CreateArticleUseCase
Creates a new CreateArticleUseCase with injected dependencies.
Sourcepub fn update_article_use_case(&self) -> UpdateArticleUseCase
pub fn update_article_use_case(&self) -> UpdateArticleUseCase
Creates a new UpdateArticleUseCase with injected dependencies.
Sourcepub fn initiate_payment_use_case(&self) -> InitiatePaymentUseCase
pub fn initiate_payment_use_case(&self) -> InitiatePaymentUseCase
Creates a new InitiatePaymentUseCase with injected dependencies.
Sourcepub fn confirm_transaction_use_case(&self) -> ConfirmTransactionUseCase
pub fn confirm_transaction_use_case(&self) -> ConfirmTransactionUseCase
Creates a new ConfirmTransactionUseCase with injected dependencies.
Sourcepub fn refund_transaction_use_case(&self) -> RefundTransactionUseCase
pub fn refund_transaction_use_case(&self) -> RefundTransactionUseCase
Creates a new RefundTransactionUseCase with injected dependencies.
Sourcepub fn grant_free_access_use_case(&self) -> GrantFreeAccessUseCase
pub fn grant_free_access_use_case(&self) -> GrantFreeAccessUseCase
Creates a new GrantFreeAccessUseCase with injected dependencies.
Sourcepub fn validate_token_use_case(&self) -> ValidateTokenUseCase
pub fn validate_token_use_case(&self) -> ValidateTokenUseCase
Creates a new ValidateTokenUseCase with injected dependencies.
Sourcepub fn revoke_access_use_case(&self) -> RevokeAccessUseCase
pub fn revoke_access_use_case(&self) -> RevokeAccessUseCase
Creates a new RevokeAccessUseCase with injected dependencies.
Sourcepub fn check_access_use_case(&self) -> CheckAccessUseCase
pub fn check_access_use_case(&self) -> CheckAccessUseCase
Creates a new CheckAccessUseCase with injected dependencies.
Sourcepub fn cleanup_expired_tokens_use_case(&self) -> CleanupExpiredTokensUseCase
pub fn cleanup_expired_tokens_use_case(&self) -> CleanupExpiredTokensUseCase
Creates a new CleanupExpiredTokensUseCase with injected dependencies.
Sourcepub fn create_fork_use_case(&self) -> CreateForkUseCase
pub fn create_fork_use_case(&self) -> CreateForkUseCase
Creates a new CreateForkUseCase with injected dependencies.
Sourcepub fn update_fork_use_case(&self) -> UpdateForkUseCase
pub fn update_fork_use_case(&self) -> UpdateForkUseCase
Creates a new UpdateForkUseCase with injected dependencies.
Sourcepub fn merge_fork_use_case(&self) -> MergeForkUseCase
pub fn merge_fork_use_case(&self) -> MergeForkUseCase
Creates a new MergeForkUseCase with injected dependencies.
Sourcepub fn discard_fork_use_case(&self) -> DiscardForkUseCase
pub fn discard_fork_use_case(&self) -> DiscardForkUseCase
Creates a new DiscardForkUseCase with injected dependencies.
Sourcepub fn get_fork_use_case(&self) -> GetForkUseCase
pub fn get_fork_use_case(&self) -> GetForkUseCase
Creates a new GetForkUseCase with injected dependencies.
Sourcepub fn append_fork_event_use_case(&self) -> AppendForkEventUseCase
pub fn append_fork_event_use_case(&self) -> AppendForkEventUseCase
Creates a new AppendForkEventUseCase with injected dependencies.
Sourcepub fn query_fork_events_use_case(&self) -> QueryForkEventsUseCase
pub fn query_fork_events_use_case(&self) -> QueryForkEventsUseCase
Creates a new QueryForkEventsUseCase with injected dependencies.
Sourcepub fn branch_fork_use_case(&self) -> BranchForkUseCase
pub fn branch_fork_use_case(&self) -> BranchForkUseCase
Creates a new BranchForkUseCase with injected dependencies.
Sourcepub fn cleanup_expired_forks_use_case(&self) -> CleanupExpiredForksUseCase
pub fn cleanup_expired_forks_use_case(&self) -> CleanupExpiredForksUseCase
Creates a new CleanupExpiredForksUseCase with injected dependencies.
Trait Implementations§
Source§impl Clone for ServiceContainer
impl Clone for ServiceContainer
Source§fn clone(&self) -> ServiceContainer
fn clone(&self) -> ServiceContainer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ServiceContainer
impl !RefUnwindSafe for ServiceContainer
impl Send for ServiceContainer
impl Sync for ServiceContainer
impl Unpin for ServiceContainer
impl !UnwindSafe for ServiceContainer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more