2020-04-17 17:53:01 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"gitlab.com/wpetit/goweb/template/html"
|
|
|
|
|
|
|
|
"forge.cadoles.com/wpetit/fake-smtp/internal/command"
|
|
|
|
"forge.cadoles.com/wpetit/fake-smtp/internal/config"
|
|
|
|
"forge.cadoles.com/wpetit/fake-smtp/internal/query"
|
|
|
|
"forge.cadoles.com/wpetit/fake-smtp/internal/storm"
|
|
|
|
"gitlab.com/wpetit/goweb/cqrs"
|
|
|
|
"gitlab.com/wpetit/goweb/service"
|
|
|
|
"gitlab.com/wpetit/goweb/service/build"
|
|
|
|
"gitlab.com/wpetit/goweb/service/template"
|
|
|
|
)
|
|
|
|
|
|
|
|
func getServiceContainer(conf *config.Config) (*service.Container, error) {
|
|
|
|
// Initialize and configure service container
|
|
|
|
ctn := service.NewContainer()
|
|
|
|
|
|
|
|
ctn.Provide(build.ServiceName, build.ServiceProvider(ProjectVersion, GitRef, BuildDate))
|
|
|
|
|
|
|
|
// Create and expose template service provider
|
|
|
|
ctn.Provide(template.ServiceName, html.ServiceProvider(
|
2020-11-03 11:48:38 +01:00
|
|
|
html.NewDirectoryLoader(conf.HTTP.TemplateDir),
|
2020-04-17 17:53:01 +02:00
|
|
|
))
|
|
|
|
|
|
|
|
// Create and expose config service provider
|
|
|
|
ctn.Provide(config.ServiceName, config.ServiceProvider(conf))
|
|
|
|
|
|
|
|
ctn.Provide(storm.ServiceName, storm.ServiceProvider(
|
|
|
|
storm.WithPath(conf.Data.Path),
|
|
|
|
))
|
|
|
|
|
|
|
|
ctn.Provide(cqrs.ServiceName, cqrs.ServiceProvider())
|
|
|
|
|
|
|
|
bus, err := cqrs.From(ctn)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
bus.RegisterCommand(
|
|
|
|
cqrs.MatchCommandRequest(&command.StoreEmailRequest{}),
|
|
|
|
cqrs.CommandHandlerFunc(command.HandleStoreEmail),
|
|
|
|
)
|
|
|
|
|
|
|
|
bus.RegisterCommand(
|
|
|
|
cqrs.MatchCommandRequest(&command.ClearInboxRequest{}),
|
|
|
|
cqrs.CommandHandlerFunc(command.HandleClearInbox),
|
|
|
|
)
|
|
|
|
|
|
|
|
bus.RegisterCommand(
|
|
|
|
cqrs.MatchCommandRequest(&command.DeleteEmailRequest{}),
|
|
|
|
cqrs.CommandHandlerFunc(command.HandleDeleteEmail),
|
|
|
|
)
|
|
|
|
|
2020-11-05 19:48:18 +01:00
|
|
|
bus.RegisterCommand(
|
|
|
|
cqrs.MatchCommandRequest(&command.RelayEmailRequest{}),
|
|
|
|
cqrs.CommandHandlerFunc(command.HandleRelayEmail),
|
|
|
|
)
|
|
|
|
|
2020-04-17 17:53:01 +02:00
|
|
|
bus.RegisterQuery(
|
|
|
|
cqrs.MatchQueryRequest(&query.GetInboxRequest{}),
|
|
|
|
cqrs.QueryHandlerFunc(query.HandleGetInbox),
|
|
|
|
)
|
|
|
|
|
|
|
|
bus.RegisterQuery(
|
|
|
|
cqrs.MatchQueryRequest(&query.OpenEmailRequest{}),
|
|
|
|
cqrs.QueryHandlerFunc(query.HandleOpenEmail),
|
|
|
|
)
|
|
|
|
|
|
|
|
return ctn, nil
|
|
|
|
}
|