50 lines
1.7 KiB
Go
50 lines
1.7 KiB
Go
|
|
// Code generated by Wire. DO NOT EDIT.
|
||
|
|
|
||
|
|
//go:generate go run -mod=mod github.com/google/wire/cmd/wire
|
||
|
|
//go:build !wireinject
|
||
|
|
// +build !wireinject
|
||
|
|
|
||
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/olezhek28/di-demo/internal/api"
|
||
|
|
"github.com/olezhek28/di-demo/internal/cache"
|
||
|
|
"github.com/olezhek28/di-demo/internal/config"
|
||
|
|
"github.com/olezhek28/di-demo/internal/database"
|
||
|
|
"github.com/olezhek28/di-demo/internal/events"
|
||
|
|
"github.com/olezhek28/di-demo/internal/repository"
|
||
|
|
"github.com/olezhek28/di-demo/internal/service"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Injectors from wire.go:
|
||
|
|
|
||
|
|
// InitializeHandler — инжектор. Wire смотрит на типы и строит граф зависимостей.
|
||
|
|
// Разработчик перечисляет провайдеры, Wire разбирается кому что нужно.
|
||
|
|
func InitializeHandler() (api.Handler, error) {
|
||
|
|
configConfig := config.AppConfig()
|
||
|
|
db, err := provideDB(configConfig)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
userRepo := repository.NewUserRepo(db)
|
||
|
|
cacheCache := provideCache(configConfig)
|
||
|
|
sessionRepo := repository.NewSessionRepo(db, cacheCache)
|
||
|
|
eventBus := events.NewEventBus()
|
||
|
|
authService := service.NewAuthService(userRepo, sessionRepo, cacheCache, eventBus)
|
||
|
|
userService := service.NewUserService(userRepo, authService, eventBus)
|
||
|
|
notificationRepo := repository.NewNotificationRepo(db)
|
||
|
|
notificationService := service.NewNotificationService(notificationRepo, userService, eventBus)
|
||
|
|
handler := api.NewHandler(userService, authService, notificationService)
|
||
|
|
return handler, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// wire.go:
|
||
|
|
|
||
|
|
func provideDB(cfg *config.Config) (database.DB, error) {
|
||
|
|
return database.New(cfg.DSN)
|
||
|
|
}
|
||
|
|
|
||
|
|
func provideCache(cfg *config.Config) cache.Cache {
|
||
|
|
return cache.New(cfg.RedisAddr)
|
||
|
|
}
|