Skip to content

[BUG] When using Dependency Injection , Iris call new method everytime to create a new struct #1564

Description

@sheunglaili

Describe the bug
When passing in New function into

app.Register(
    environment.New
    // ...dependencies
)

When requesting endpoints , the New function will run again. Shouldn't the result of the new constructor be stored in some kind of bean factory instead ?

To Reproduce
Steps to reproduce the behavior:

  1. Create a Iris project.
  2. Setup mvc.
  3. in the Dependencies new function fmt.Println some sentences
  4. register dependencies in the mvc
  5. register the controller and use the dependencies in that controller
  6. start the application and request the endpoint
  7. should see println in New function print out everytime when requesting endpoint.

Expected behavior
New function should be called once only , but not everytime when there is request.

Screenshots
Screenshot 2020-07-21 at 11 00 49 AM

the Json is the configuration I printed from environment struct new function.
the line beneath it is the log in controller method

Desktop (please complete the following information):

  • OS: MAC

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions