فهرست منبع

修改型木结构

yjp 1 سال پیش
والد
کامیت
833deb7862

+ 2 - 20
examples/examples/project/application/application.go

@@ -31,27 +31,9 @@ func DestroyApp() {
 	appInstance = nil
 }
 
-type Service interface {
-	Init(appInstance *application.App) error
-	Destroy() error
-}
-
-var services = []Service{
-	&service.VersionService{},
-	&service.ConfigurationService{},
-	&service.ClassService{},
-	&service.StudentService{},
-	&service.IdentityService{},
-	&service.FamilyService{},
-	&service.ClassAndStudentService{},
-	&service.StudentAndFamilyService{},
-	&service.StudentAndIdentityService{},
-	&service.StudentAndHobbyService{},
-}
-
 func Start() error {
 	// 初始化服务
-	for _, svc := range services {
+	for _, svc := range service.RegisteredServices {
 		err := svc.Init(appInstance)
 		if err != nil {
 			return err
@@ -73,7 +55,7 @@ func Finish() error {
 	}
 
 	// 销毁服务
-	for _, svc := range services {
+	for _, svc := range service.RegisteredServices {
 		err := svc.Destroy()
 		if err != nil {
 			return err

+ 4 - 1
examples/examples/project/application/service/class.go

@@ -3,9 +3,12 @@ package service
 import (
 	"git.sxidc.com/go-framework/baize/convenient/entity_crud"
 	"git.sxidc.com/go-framework/baize/examples/examples/project/application/domain/class"
+	"git.sxidc.com/go-framework/baize/framwork/binding"
 	"git.sxidc.com/go-framework/baize/framwork/core/application"
 )
 
+var classService = &ClassService{}
+
 type ClassService struct{}
 
 func (svc *ClassService) Init(appInstance *application.App) error {
@@ -18,7 +21,7 @@ func (svc *ClassService) Destroy() error {
 }
 
 func (svc *ClassService) v1(appInstance *application.App) {
-	v1Binder := appInstance.Binder(application.RouterPrefix, "v1")
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	entity_crud.BindSimple[class.Info](v1Binder, &entity_crud.Simple[class.Info]{
 		Entity:             &class.Entity{},

+ 4 - 1
examples/examples/project/application/service/class_and_student.go

@@ -4,9 +4,12 @@ import (
 	"git.sxidc.com/go-framework/baize/convenient/relation/one2many"
 	"git.sxidc.com/go-framework/baize/examples/examples/project/application/domain/class"
 	"git.sxidc.com/go-framework/baize/examples/examples/project/application/domain/student"
+	"git.sxidc.com/go-framework/baize/framwork/binding"
 	"git.sxidc.com/go-framework/baize/framwork/core/application"
 )
 
+var classAndStudentService = &ClassAndStudentService{}
+
 type ClassAndStudentService struct{}
 
 func (svc *ClassAndStudentService) Init(appInstance *application.App) error {
@@ -19,7 +22,7 @@ func (svc *ClassAndStudentService) Destroy() error {
 }
 
 func (svc *ClassAndStudentService) v1(appInstance *application.App) {
-	v1Binder := appInstance.Binder(application.RouterPrefix, "v1")
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	one2many.BindSimple(v1Binder, &one2many.Simple[class.Info, student.Info]{
 		Left:                          &class.Entity{},

+ 4 - 1
examples/examples/project/application/service/configuration.go

@@ -2,9 +2,12 @@ package service
 
 import (
 	"git.sxidc.com/go-framework/baize/convenient/domain/configuration"
+	"git.sxidc.com/go-framework/baize/framwork/binding"
 	"git.sxidc.com/go-framework/baize/framwork/core/application"
 )
 
+var configurationService = &ConfigurationService{}
+
 type ConfigurationService struct{}
 
 func (svc *ConfigurationService) Init(appInstance *application.App) error {
@@ -17,7 +20,7 @@ func (svc *ConfigurationService) Destroy() error {
 }
 
 func (svc *ConfigurationService) prefixRoot(appInstance *application.App) {
-	prefixRootBinder := appInstance.Binder(application.RouterPrefix, "")
+	prefixRootBinder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, ""), appInstance.Infrastructure())
 	configuration.BindConfiguration(prefixRootBinder, &configuration.Simple{
 		Schema: dbSchema,
 	})

+ 4 - 1
examples/examples/project/application/service/family.go

@@ -3,9 +3,12 @@ package service
 import (
 	"git.sxidc.com/go-framework/baize/convenient/entity_crud"
 	"git.sxidc.com/go-framework/baize/examples/examples/project/application/domain/family"
+	"git.sxidc.com/go-framework/baize/framwork/binding"
 	"git.sxidc.com/go-framework/baize/framwork/core/application"
 )
 
+var familyService = &FamilyService{}
+
 type FamilyService struct{}
 
 func (svc *FamilyService) Init(appInstance *application.App) error {
@@ -18,7 +21,7 @@ func (svc *FamilyService) Destroy() error {
 }
 
 func (svc *FamilyService) v1(appInstance *application.App) {
-	v1Binder := appInstance.Binder(application.RouterPrefix, "v1")
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	entity_crud.BindSimple[family.Info](v1Binder, &entity_crud.Simple[family.Info]{
 		Entity:             &family.Entity{},

+ 4 - 1
examples/examples/project/application/service/identity.go

@@ -3,9 +3,12 @@ package service
 import (
 	"git.sxidc.com/go-framework/baize/convenient/entity_crud"
 	"git.sxidc.com/go-framework/baize/examples/examples/project/application/domain/identity"
+	"git.sxidc.com/go-framework/baize/framwork/binding"
 	"git.sxidc.com/go-framework/baize/framwork/core/application"
 )
 
+var identityService = &IdentityService{}
+
 type IdentityService struct{}
 
 func (svc *IdentityService) Init(appInstance *application.App) error {
@@ -18,7 +21,7 @@ func (svc *IdentityService) Destroy() error {
 }
 
 func (svc *IdentityService) v1(appInstance *application.App) {
-	v1Binder := appInstance.Binder(application.RouterPrefix, "v1")
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	entity_crud.BindSimple[identity.Info](v1Binder, &entity_crud.Simple[identity.Info]{
 		Entity:             &identity.Entity{},

+ 20 - 0
examples/examples/project/application/service/service.go

@@ -1,5 +1,25 @@
 package service
 
+import "git.sxidc.com/go-framework/baize/framwork/core/application"
+
 const (
 	dbSchema = "test"
 )
+
+type Service interface {
+	Init(appInstance *application.App) error
+	Destroy() error
+}
+
+var RegisteredServices = []Service{
+	versionService,
+	configurationService,
+	classService,
+	studentService,
+	identityService,
+	familyService,
+	classAndStudentService,
+	studentAndFamilyService,
+	studentAndIdentityService,
+	studentAndHobbyService,
+}

+ 4 - 1
examples/examples/project/application/service/student.go

@@ -3,9 +3,12 @@ package service
 import (
 	"git.sxidc.com/go-framework/baize/convenient/entity_crud"
 	"git.sxidc.com/go-framework/baize/examples/examples/project/application/domain/student"
+	"git.sxidc.com/go-framework/baize/framwork/binding"
 	"git.sxidc.com/go-framework/baize/framwork/core/application"
 )
 
+var studentService = &StudentService{}
+
 type StudentService struct{}
 
 func (svc *StudentService) Init(appInstance *application.App) error {
@@ -18,7 +21,7 @@ func (svc *StudentService) Destroy() error {
 }
 
 func (svc *StudentService) v1(appInstance *application.App) {
-	v1Binder := appInstance.Binder(application.RouterPrefix, "v1")
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	entity_crud.BindSimple[student.Info](v1Binder, &entity_crud.Simple[student.Info]{
 		Entity:             &student.Entity{},

+ 4 - 1
examples/examples/project/application/service/student_and_family.go

@@ -4,9 +4,12 @@ import (
 	"git.sxidc.com/go-framework/baize/convenient/relation/one2one"
 	"git.sxidc.com/go-framework/baize/examples/examples/project/application/domain/family"
 	"git.sxidc.com/go-framework/baize/examples/examples/project/application/domain/student"
+	"git.sxidc.com/go-framework/baize/framwork/binding"
 	"git.sxidc.com/go-framework/baize/framwork/core/application"
 )
 
+var studentAndFamilyService = &StudentAndFamilyService{}
+
 type StudentAndFamilyService struct{}
 
 func (svc *StudentAndFamilyService) Init(appInstance *application.App) error {
@@ -19,7 +22,7 @@ func (svc *StudentAndFamilyService) Destroy() error {
 }
 
 func (svc *StudentAndFamilyService) v1(appInstance *application.App) {
-	v1Binder := appInstance.Binder(application.RouterPrefix, "v1")
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	one2one.BindSimple(v1Binder, &one2one.Simple[student.Info, family.Info]{
 		Left:                          &student.Entity{},

+ 4 - 1
examples/examples/project/application/service/student_and_hobby.go

@@ -4,9 +4,12 @@ import (
 	"git.sxidc.com/go-framework/baize/convenient/relation/remote"
 	"git.sxidc.com/go-framework/baize/examples/examples/project/application/domain/hobby"
 	"git.sxidc.com/go-framework/baize/examples/examples/project/application/domain/student"
+	"git.sxidc.com/go-framework/baize/framwork/binding"
 	"git.sxidc.com/go-framework/baize/framwork/core/application"
 )
 
+var studentAndHobbyService = &StudentAndHobbyService{}
+
 type StudentAndHobbyService struct{}
 
 func (svc *StudentAndHobbyService) Init(appInstance *application.App) error {
@@ -19,7 +22,7 @@ func (svc *StudentAndHobbyService) Destroy() error {
 }
 
 func (svc *StudentAndHobbyService) v1(appInstance *application.App) {
-	v1Binder := appInstance.Binder(application.RouterPrefix, "v1")
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	remote.BindSimple(v1Binder, &remote.Simple[student.Info, string]{
 		Left:                  &student.Entity{},

+ 4 - 1
examples/examples/project/application/service/student_and_identity.go

@@ -4,9 +4,12 @@ import (
 	"git.sxidc.com/go-framework/baize/convenient/relation/many2many"
 	"git.sxidc.com/go-framework/baize/examples/examples/project/application/domain/identity"
 	"git.sxidc.com/go-framework/baize/examples/examples/project/application/domain/student"
+	"git.sxidc.com/go-framework/baize/framwork/binding"
 	"git.sxidc.com/go-framework/baize/framwork/core/application"
 )
 
+var studentAndIdentityService = &StudentAndIdentityService{}
+
 type StudentAndIdentityService struct{}
 
 func (svc *StudentAndIdentityService) Init(appInstance *application.App) error {
@@ -19,7 +22,7 @@ func (svc *StudentAndIdentityService) Destroy() error {
 }
 
 func (svc *StudentAndIdentityService) v1(appInstance *application.App) {
-	v1Binder := appInstance.Binder(application.RouterPrefix, "v1")
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	many2many.BindSimple(v1Binder, &many2many.Simple[student.Info, identity.Info]{
 		Left:                  &student.Entity{},

+ 3 - 1
examples/examples/project/application/service/version.go

@@ -10,6 +10,8 @@ import (
 	"git.sxidc.com/go-framework/baize/framwork/core/infrastructure"
 )
 
+var versionService = &VersionService{}
+
 type VersionService struct{}
 
 func (svc *VersionService) Init(appInstance *application.App) error {
@@ -22,7 +24,7 @@ func (svc *VersionService) Destroy() error {
 }
 
 func (svc *VersionService) prefixRoot(appInstance *application.App) {
-	prefixRootBinder := appInstance.Binder(application.RouterPrefix, "")
+	prefixRootBinder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, ""), appInstance.Infrastructure())
 
 	binding.GetBind(prefixRootBinder, &binding.SimpleBindItem[map[string]any]{
 		Path:         "/version",

+ 4 - 4
framwork/core/application/application.go

@@ -1,7 +1,6 @@
 package application
 
 import (
-	"git.sxidc.com/go-framework/baize/framwork/binding"
 	"git.sxidc.com/go-framework/baize/framwork/core/api"
 	"git.sxidc.com/go-framework/baize/framwork/core/infrastructure"
 	"git.sxidc.com/go-framework/baize/framwork/core/infrastructure/logger"
@@ -67,9 +66,10 @@ const (
 	RouterPrefix = "prefix"
 )
 
-// Binder 创建Binder
-func (app *App) Binder(routerType string, version string) *binding.Binder {
+// ChooseRouter 选择Router
+func (app *App) ChooseRouter(routerType string, version string) api.Router {
 	var router api.Router
+
 	switch routerType {
 	case RouterRoot:
 		router = app.Api().RootRouter()
@@ -83,5 +83,5 @@ func (app *App) Binder(routerType string, version string) *binding.Binder {
 		router = router.VersionedRouter(version)
 	}
 
-	return binding.NewBinder(router, app.infrastructureInstance)
+	return router
 }