123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package service_provider
- import (
- "github.com/dmitriygnatenko/internal/interfaces"
- "github.com/dmitriygnatenko/internal/repositories"
- cacheService "github.com/dmitriygnatenko/internal/services/cache"
- dbService "github.com/dmitriygnatenko/internal/services/db"
- envService "github.com/dmitriygnatenko/internal/services/env"
- mailService "github.com/dmitriygnatenko/internal/services/mailer"
- )
- type ServiceProvider struct {
- env interfaces.IEnv
- cache interfaces.ICache
- mailer interfaces.IMailer
- articleRepository interfaces.IArticleRepository
- tagRepository interfaces.ITagRepository
- articleTagRepository interfaces.IArticleTagRepository
- }
- func Init() (*ServiceProvider, error) {
- sp := &ServiceProvider{}
- // Init env service
- env, err := envService.Init()
- if err != nil {
- return nil, err
- }
- sp.env = env
- 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)
- // Init cache service
- sp.cache = cacheService.Init()
- // Init mailer
- sp.mailer = mailService.Init(sp.env)
- return sp, nil
- }
- func (sp *ServiceProvider) GetEnvService() interfaces.IEnv {
- return sp.env
- }
- func (sp *ServiceProvider) GetCacheService() interfaces.ICache {
- return sp.cache
- }
- func (sp *ServiceProvider) GetMailerService() interfaces.IMailer {
- return sp.mailer
- }
- func (sp *ServiceProvider) GetArticleRepository() interfaces.IArticleRepository {
- return sp.articleRepository
- }
- func (sp *ServiceProvider) GetTagRepository() interfaces.ITagRepository {
- return sp.tagRepository
- }
- func (sp *ServiceProvider) GetArticleTagRepository() interfaces.IArticleTagRepository {
- return sp.articleTagRepository
- }
|