1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package sp
- import (
- "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/repositories"
- authService "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/auth"
- cacheService "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/cache"
- dbService "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/db"
- envService "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/env"
- mailService "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/mailer"
- )
- type ServiceProvider struct {
- env *envService.Service
- cache *cacheService.Service
- mailer *mailService.Service
- auth *authService.Service
- articleRepository *repositories.ArticleRepository
- tagRepository *repositories.TagRepository
- articleTagRepository *repositories.ArticleTagRepository
- userRepository *repositories.UserRepository
- }
- func Init() (*ServiceProvider, error) {
- sp := &ServiceProvider{}
- // Init services
- env, err := envService.Init()
- if err != nil {
- return nil, err
- }
- sp.env = env
- cache, err := cacheService.Init()
- if err != nil {
- return nil, err
- }
- sp.cache = cache
- mailer, err := mailService.Init(sp.env)
- if err != nil {
- return nil, err
- }
- sp.mailer = mailer
- auth, err := authService.Init(sp.env)
- if err != nil {
- return nil, err
- }
- sp.auth = auth
- db, err := dbService.Init(env)
- if err != nil {
- return nil, err
- }
- // Init repositories
- sp.articleRepository = repositories.InitArticleRepository(db)
- sp.tagRepository = repositories.InitTagRepository(db)
- sp.articleTagRepository = repositories.InitArticleTagRepository(db)
- sp.userRepository = repositories.InitUserRepository(db)
- return sp, nil
- }
- func (sp *ServiceProvider) EnvService() *envService.Service {
- return sp.env
- }
- func (sp *ServiceProvider) CacheService() *cacheService.Service {
- return sp.cache
- }
- func (sp *ServiceProvider) MailerService() *mailService.Service {
- return sp.mailer
- }
- func (sp *ServiceProvider) AuthService() *authService.Service {
- return sp.auth
- }
- func (sp *ServiceProvider) ArticleRepository() *repositories.ArticleRepository {
- return sp.articleRepository
- }
- func (sp *ServiceProvider) TagRepository() *repositories.TagRepository {
- return sp.tagRepository
- }
- func (sp *ServiceProvider) ArticleTagRepository() *repositories.ArticleTagRepository {
- return sp.articleTagRepository
- }
- func (sp *ServiceProvider) UserRepository() *repositories.UserRepository {
- return sp.userRepository
- }
|