chrly/di/dispatcher.go

37 lines
920 B
Go
Raw Normal View History

2020-04-16 22:12:38 +05:30
package di
import (
"github.com/goava/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"
"github.com/elyby/chrly/mojangtextures"
)
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(mojangtextures.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,
) {
// TODO: use idea from https://github.com/goava/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
}