yjp преди 1 година
родител
ревизия
a228f3cb5b

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

@@ -4,6 +4,7 @@ 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/framework/binding"
+	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/core/application"
 )
 
@@ -21,7 +22,7 @@ func (svc *ClassService) Destroy() error {
 }
 
 func (svc *ClassService) v1(appInstance *application.App) {
-	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	entity_crud.BindSimple[class.Info](v1Binder, &entity_crud.Simple[class.Info]{
 		Entity:             &class.Entity{},

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

@@ -5,6 +5,7 @@ import (
 	"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/framework/binding"
+	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/core/application"
 )
 
@@ -22,7 +23,7 @@ func (svc *ClassAndStudentService) Destroy() error {
 }
 
 func (svc *ClassAndStudentService) v1(appInstance *application.App) {
-	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	one2many.BindSimple(v1Binder, &one2many.Simple[class.Info, student.Info]{
 		Left:                          &class.Entity{},

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

@@ -3,6 +3,7 @@ package service
 import (
 	"git.sxidc.com/go-framework/baize/convenient/domain/configuration"
 	"git.sxidc.com/go-framework/baize/framework/binding"
+	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/core/application"
 )
 
@@ -20,7 +21,7 @@ func (svc *ConfigurationService) Destroy() error {
 }
 
 func (svc *ConfigurationService) prefixRoot(appInstance *application.App) {
-	prefixRootBinder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, ""), appInstance.Infrastructure())
+	prefixRootBinder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, ""), appInstance.Infrastructure())
 	configuration.BindConfiguration(prefixRootBinder, &configuration.Simple{
 		Schema: dbSchema,
 	})

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

@@ -4,6 +4,7 @@ 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/framework/binding"
+	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/core/application"
 )
 
@@ -21,7 +22,7 @@ func (svc *FamilyService) Destroy() error {
 }
 
 func (svc *FamilyService) v1(appInstance *application.App) {
-	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	entity_crud.BindSimple[family.Info](v1Binder, &entity_crud.Simple[family.Info]{
 		Entity:             &family.Entity{},

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

@@ -4,6 +4,7 @@ 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/framework/binding"
+	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/core/application"
 )
 
@@ -21,7 +22,7 @@ func (svc *IdentityService) Destroy() error {
 }
 
 func (svc *IdentityService) v1(appInstance *application.App) {
-	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	entity_crud.BindSimple[identity.Info](v1Binder, &entity_crud.Simple[identity.Info]{
 		Entity:             &identity.Entity{},

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

@@ -4,6 +4,7 @@ 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/framework/binding"
+	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/core/application"
 )
 
@@ -21,7 +22,7 @@ func (svc *StudentService) Destroy() error {
 }
 
 func (svc *StudentService) v1(appInstance *application.App) {
-	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	entity_crud.BindSimple[student.Info](v1Binder, &entity_crud.Simple[student.Info]{
 		Entity:             &student.Entity{},

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

@@ -5,6 +5,7 @@ import (
 	"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/framework/binding"
+	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/core/application"
 )
 
@@ -22,7 +23,7 @@ func (svc *StudentAndFamilyService) Destroy() error {
 }
 
 func (svc *StudentAndFamilyService) v1(appInstance *application.App) {
-	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	one2one.BindSimple(v1Binder, &one2one.Simple[student.Info, family.Info]{
 		Left:                          &student.Entity{},

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

@@ -5,6 +5,7 @@ import (
 	"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/framework/binding"
+	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/core/application"
 )
 
@@ -22,7 +23,7 @@ func (svc *StudentAndHobbyService) Destroy() error {
 }
 
 func (svc *StudentAndHobbyService) v1(appInstance *application.App) {
-	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	remote.BindSimple(v1Binder, &remote.Simple[student.Info, string]{
 		Left:                  &student.Entity{},

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

@@ -5,6 +5,7 @@ import (
 	"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/framework/binding"
+	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/core/application"
 )
 
@@ -22,7 +23,7 @@ func (svc *StudentAndIdentityService) Destroy() error {
 }
 
 func (svc *StudentAndIdentityService) v1(appInstance *application.App) {
-	v1Binder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, "v1"), appInstance.Infrastructure())
+	v1Binder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, "v1"), appInstance.Infrastructure())
 
 	many2many.BindSimple(v1Binder, &many2many.Simple[student.Info, identity.Info]{
 		Left:                  &student.Entity{},

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

@@ -24,7 +24,7 @@ func (svc *VersionService) Destroy() error {
 }
 
 func (svc *VersionService) prefixRoot(appInstance *application.App) {
-	prefixRootBinder := binding.NewBinder(appInstance.ChooseRouter(application.RouterPrefix, ""), appInstance.Infrastructure())
+	prefixRootBinder := binding.NewBinder(appInstance.ChooseRouter(api.RouterPrefix, ""), appInstance.Infrastructure())
 
 	binding.GetBind(prefixRootBinder, &binding.SimpleBindItem[map[string]any]{
 		Path:         "/version",

+ 24 - 0
framework/core/api/api.go

@@ -75,3 +75,27 @@ func (api *Api) PrefixRouter() Router {
 
 	return api.prefixRouter
 }
+
+const (
+	RouterRoot   = "root"
+	RouterPrefix = "prefix"
+)
+
+func (api *Api) ChooseRouter(routerType string, version string) Router {
+	var router Router
+
+	switch routerType {
+	case RouterRoot:
+		router = api.RootRouter()
+	case RouterPrefix:
+		router = api.PrefixRouter()
+	default:
+		router = api.PrefixRouter()
+	}
+
+	if strutils.IsStringNotEmpty(version) {
+		router = router.VersionedRouter(version)
+	}
+
+	return router
+}

+ 1 - 22
framework/core/application/application.go

@@ -4,7 +4,6 @@ import (
 	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/core/infrastructure"
 	"git.sxidc.com/go-framework/baize/framework/core/infrastructure/logger"
-	"git.sxidc.com/go-tools/utils/strutils"
 )
 
 type App struct {
@@ -61,27 +60,7 @@ func (app *App) Logger() *logger.Logger {
 	return app.loggerInstance
 }
 
-const (
-	RouterRoot   = "root"
-	RouterPrefix = "prefix"
-)
-
 // ChooseRouter 选择Router
 func (app *App) ChooseRouter(routerType string, version string) api.Router {
-	var router api.Router
-
-	switch routerType {
-	case RouterRoot:
-		router = app.Api().RootRouter()
-	case RouterPrefix:
-		router = app.Api().PrefixRouter()
-	default:
-		router = app.Api().PrefixRouter()
-	}
-
-	if strutils.IsStringNotEmpty(version) {
-		router = router.VersionedRouter(version)
-	}
-
-	return router
+	return app.Api().ChooseRouter(routerType, version)
 }