Post

GoLangGoLang

v
veerubhotla sowmithri

Posted on 25th April 2024|69 views

0
votes

Golang Dependency Injection

What is dependency injection in Golang?

Answers
P
kumar san

Posted on 25th April 2024

Dependency Injection means the view that your components which are usual structs within go should get their dependencies while being built. That runs counter over the associated anti-pattern like components making their private dependencies through initialization. Let us see at an example.

type Server struct {

  config *Config

}

func New() *Server {

  return &Server{

    config: buildConfigAnyhow(),

  }

}

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos