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,32 +2,35 @@ package application
import (
"mayfly-go/internal/sys/infrastructure/persistence"
"mayfly-go/pkg/ioc"
)
var (
accountApp = newAccountApp(persistence.GetAccountRepo())
configApp = newConfigApp(persistence.GetConfigRepo())
resourceApp = newResourceApp(persistence.GetResourceRepo())
roleApp = newRoleApp(persistence.GetRoleRepo(), persistence.GetAccountRoleRepo())
syslogApp = newSyslogApp(persistence.GetSyslogRepo())
)
func init() {
persistence.Init()
ioc.Register(new(accountAppImpl), ioc.WithComponentName("AccountApp"))
ioc.Register(new(roleAppImpl), ioc.WithComponentName("RoleApp"))
ioc.Register(new(configAppImpl), ioc.WithComponentName("ConfigApp"))
ioc.Register(new(resourceAppImpl), ioc.WithComponentName("ResourceApp"))
ioc.Register(new(syslogAppImpl), ioc.WithComponentName("SyslogApp"))
}
func GetAccountApp() Account {
return accountApp
return ioc.Get[Account]("AccountApp")
}
func GetConfigApp() Config {
return configApp
return ioc.Get[Config]("ConfigApp")
}
func GetResourceApp() Resource {
return resourceApp
return ioc.Get[Resource]("ResourceApp")
}
func GetRoleApp() Role {
return roleApp
return ioc.Get[Role]("RoleApp")
}
func GetSyslogApp() Syslog {
return syslogApp
return ioc.Get[Syslog]("SyslogApp")
}