chrly/di/dispatcher.go

35 lines
843 B
Go
Raw Normal View History

2020-04-16 22:12:38 +05:30
package di
import (
2023-12-13 21:59:12 +05:30
"github.com/defval/di"
"github.com/mono83/slf"
2020-04-16 22:12:38 +05:30
d "github.com/elyby/chrly/dispatcher"
"github.com/elyby/chrly/eventsubscribers"
2020-04-16 22:12:38 +05:30
"github.com/elyby/chrly/http"
)
var dispatcher = di.Options(
di.Provide(newDispatcher,
di.As(new(d.Emitter)),
di.As(new(d.Subscriber)),
2020-04-16 22:12:38 +05:30
di.As(new(http.Emitter)),
di.As(new(eventsubscribers.Subscriber)),
2020-04-16 22:12:38 +05:30
),
di.Invoke(enableEventsHandlers),
2020-04-16 22:12:38 +05:30
)
func newDispatcher() d.Dispatcher {
return d.New()
}
func enableEventsHandlers(
dispatcher d.Subscriber,
logger slf.Logger,
statsReporter slf.StatsReporter,
) {
2023-12-13 21:59:12 +05:30
// TODO: use idea from https://github.com/defval/di/issues/10#issuecomment-615869852
(&eventsubscribers.Logger{Logger: logger}).ConfigureWithDispatcher(dispatcher)
(&eventsubscribers.StatsReporter{StatsReporter: statsReporter}).ConfigureWithDispatcher(dispatcher)
2020-04-16 22:12:38 +05:30
}