feat: 新增简易版ioc

This commit is contained in:
meilin.huang
2024-01-21 22:52:20 +08:00
parent f4a64b96a9
commit f27d3d200f
106 changed files with 815 additions and 707 deletions

View File

@@ -2,12 +2,15 @@ package application
import (
"mayfly-go/internal/msg/infrastructure/persistence"
"mayfly-go/pkg/ioc"
)
var (
msgApp = newMsgApp(persistence.GetMsgRepo())
)
func init() {
persistence.Init()
ioc.Register(new(msgAppImpl), ioc.WithComponentName("MsgApp"))
}
func GetMsgApp() Msg {
return msgApp
return ioc.Get[Msg]("MsgApp")
}

View File

@@ -19,27 +19,21 @@ type Msg interface {
CreateAndSend(la *model.LoginAccount, msg *dto.SysMsg)
}
func newMsgApp(msgRepo repository.Msg) Msg {
return &msgAppImpl{
msgRepo: msgRepo,
}
}
type msgAppImpl struct {
msgRepo repository.Msg
MsgRepo repository.Msg `inject:""`
}
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return a.msgRepo.GetPageList(condition, pageParam, toEntity)
return a.MsgRepo.GetPageList(condition, pageParam, toEntity)
}
func (a *msgAppImpl) Create(ctx context.Context, msg *entity.Msg) {
a.msgRepo.Insert(ctx, msg)
a.MsgRepo.Insert(ctx, msg)
}
func (a *msgAppImpl) CreateAndSend(la *model.LoginAccount, wmsg *dto.SysMsg) {
now := time.Now()
msg := &entity.Msg{Type: 2, Msg: wmsg.Msg, RecipientId: int64(la.Id), CreateTime: &now, CreatorId: la.Id, Creator: la.Username}
a.msgRepo.Insert(context.TODO(), msg)
a.MsgRepo.Insert(context.TODO(), msg)
ws.SendJsonMsg(ws.UserId(la.Id), wmsg.ClientId, wmsg)
}