-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathdi.rs
146 lines (130 loc) · 4.81 KB
/
di.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
use crate::app::features::article::presenters::ArticlePresenterImpl;
use crate::app::features::article::repositories::ArticleRepositoryImpl;
use crate::app::features::article::usecases::ArticleUsecase;
use crate::app::features::comment::presenters::CommentPresenterImpl;
use crate::app::features::comment::repositories::CommentRepositoryImpl;
use crate::app::features::comment::usecases::CommentUsecase;
use crate::app::features::favorite::presenters::FavoritePresenterImpl;
use crate::app::features::favorite::repositories::FavoriteRepositoryImpl;
use crate::app::features::favorite::usecases::FavoriteUsecase;
use crate::app::features::profile::presenters::ProfilePresenterImpl;
use crate::app::features::profile::repositories::ProfileRepositoryImpl;
use crate::app::features::profile::usecases::ProfileUsecase;
use crate::app::features::tag::presenters::TagPresenterImpl;
use crate::app::features::tag::repositories::TagRepositoryImpl;
use crate::app::features::tag::usecases::TagUsecase;
use crate::app::features::user::presenters::UserPresenterImpl;
use crate::app::features::user::repositories::UserRepositoryImpl;
use crate::app::features::user::usecases::UserUsecase;
use std::sync::Arc;
use crate::utils::db::DbPool;
#[derive(Clone)]
pub struct DiContainer {
/**
* User
*/
pub user_repository: UserRepositoryImpl,
pub user_usecase: UserUsecase,
pub user_presenter: UserPresenterImpl,
/**
* Profile
*/
pub profile_repository: ProfileRepositoryImpl,
pub profile_presenter: ProfilePresenterImpl,
pub profile_usecase: ProfileUsecase,
/**
* Favorite
*/
pub favorite_repository: FavoriteRepositoryImpl,
pub favorite_presenter: FavoritePresenterImpl,
pub favorite_usecase: FavoriteUsecase,
/**
* Article
*/
pub article_repository: ArticleRepositoryImpl,
pub article_presenter: ArticlePresenterImpl,
pub article_usecase: ArticleUsecase,
/**
* Tag
*/
pub tag_repository: TagRepositoryImpl,
pub tag_presenter: TagPresenterImpl,
pub tag_usecase: TagUsecase,
/**
* Comment
*/
pub comment_repository: CommentRepositoryImpl,
pub comment_presenter: CommentPresenterImpl,
pub comment_usecase: CommentUsecase,
}
impl DiContainer {
pub fn new(pool: &DbPool) -> Self {
// Repository
let user_repository = UserRepositoryImpl::new(pool.clone());
let profile_repository = ProfileRepositoryImpl::new(pool.clone());
let favorite_repository = FavoriteRepositoryImpl::new(pool.clone());
let article_repository = ArticleRepositoryImpl::new(pool.clone());
let tag_repository = TagRepositoryImpl::new(pool.clone());
let comment_repository = CommentRepositoryImpl::new(pool.clone());
// Presenter
let user_presenter = UserPresenterImpl::new();
let profile_presenter = ProfilePresenterImpl::new();
let favorite_presenter = FavoritePresenterImpl::new();
let article_presenter = ArticlePresenterImpl::new();
let tag_presenter = TagPresenterImpl::new();
let comment_presenter = CommentPresenterImpl::new();
// Usecase
let user_usecase = UserUsecase::new(
Arc::new(user_repository.clone()),
Arc::new(user_presenter.clone()),
);
let profile_usecase = ProfileUsecase::new(
Arc::new(profile_repository.clone()),
Arc::new(user_repository.clone()),
Arc::new(profile_presenter.clone()),
);
let favorite_usecase = FavoriteUsecase::new(
Arc::new(favorite_repository.clone()),
Arc::new(favorite_presenter.clone()),
Arc::new(article_repository.clone()),
);
let article_usecase = ArticleUsecase::new(
Arc::new(article_repository.clone()),
Arc::new(article_presenter.clone()),
);
let tag_usecase = TagUsecase::new(
Arc::new(tag_repository.clone()),
Arc::new(tag_presenter.clone()),
);
let comment_usecase = CommentUsecase::new(
Arc::new(comment_repository.clone()),
Arc::new(comment_presenter.clone()),
);
Self {
// User
user_repository,
user_usecase,
user_presenter,
// Profile
profile_presenter,
profile_repository,
profile_usecase,
// Favorite
favorite_repository,
favorite_presenter,
favorite_usecase,
// Article
article_repository,
article_presenter,
article_usecase,
// Tag
tag_repository,
tag_presenter,
tag_usecase,
// Comment
comment_repository,
comment_presenter,
comment_usecase,
}
}
}