Skip to content

how to resolve dependency from api.Container #2555

Open
@shyandsy

Description

@shyandsy

senario

initialize dependencies

  1. dependency: config loader
  2. dependency: jwt, it will get config information from config loader

use middleware in dependency jwt

problem is How can i resolve dependencies in main() ?

func main() {
	app := iris.New()

	//jwtSvc := feature.NewJWTService("your-secret-key", "myxtea")
	//app.RegisterDependency(func() feature.JWTService {
	//	return jwtSvc
	//})

	feature.ProvideConfigLoader(app)
	feature.ProvideDatabase(app)
	feature.ProvideJWTService(app)

	app.ConfigureContainer(func(api *iris.APIContainer) {

		// I can see my dependencies injected before
		for _, dependency := range api.Container.Dependencies {
			fmt.Println(dependency.String())
                 }
                 ............

it looks there is no such Get ore Resolve method for api.Container

any other solutions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions