You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package service
// +ioc:aop:before=Run-awesomeProject/aop.Advice1:Before
// +ioc:aop:after=Run-awesomeProject/aop.Advice1:After
type IService interface {
Run(int)
}
awesomeProject/service/impl/service_impl.go
package impl
import "fmt"
// +ioc:autowire=true
// +ioc:autowire:type=allimpls
// +ioc:autowire:implements=awesomeProject/service.IService
type ServiceImpl1 struct {
}
func (s ServiceImpl1) Run(i int) {
fmt.Printf("this is ServiceImpl1 Run(%d)\n", i)
}
// +ioc:autowire=true
// +ioc:autowire:type=allimpls
// +ioc:autowire:implements=awesomeProject/service.IService
type ServiceImpl2 struct {
}
func (s ServiceImpl2) Run(i int) {
fmt.Printf("this is ServiceImpl2 Run(%d)\n", i)
}
awesomeProject/main.go
package main
import (
"awesomeProject/service"
"github.com/alibaba/ioc-golang"
)
func main() {
// start
if err := ioc.Load(); err != nil {
panic(err)
}
// app, err := GetAppIOCInterfaceSingleton is ok too
app, err := GetAppSingleton()
if err != nil {
panic(err)
}
app.Run()
}
// +ioc:autowire=true
// +ioc:autowire:type=singleton
type App struct {
Services []service.IService `allimpls:""`
}
func (a *App) Run() {
for i := range a.Services {
a.Services[i].Run(i + 100)
}
}
Expected results:
Advice1 Before:func(100)
this is ServiceImpl1 Run(100)
Advice1 After:func(100)
Advice1 Before:func(101)
this is ServiceImpl2 Run(101)
Advice1 After:func(101)
The text was updated successfully, but these errors were encountered:
Thanks, that's a good design, but interfece-based annotation now is not supported in our framework, which may causes some time to design, do you have any good idea? @zhanjunjie2019
awesomeProject/ctx/ctx.go
awesomeProject/aop/advice.go
awesomeProject/service/service.go
awesomeProject/service/impl/service_impl.go
awesomeProject/main.go
Expected results:
The text was updated successfully, but these errors were encountered: