Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

will add dependency injection future? #377

Open
zhuxiujia opened this issue Apr 11, 2020 · 2 comments
Open

will add dependency injection future? #377

zhuxiujia opened this issue Apr 11, 2020 · 2 comments

Comments

@zhuxiujia
Copy link

zhuxiujia commented Apr 11, 2020

will add dependency injection future?

same like :

struct Service{}
impl Service{
  pub fn println();
}

struct Bean{
     service:Option<RefCell<Service>>// this field is  dependency injection
}

impl Bean{
  pub fn doSomeThing(&mut self){
         // call the dependency injection service
         self.service.println()....
  }
}

let service=Service{}
let bean=Bean{}
actix.inject(service)
actix.inject(bean)
// when dependency injection finish,  call bean.doSomeThing() will success.
@fMeow
Copy link
Member

fMeow commented Jun 23, 2020

Would you please add some detail about the scenario where dependency injection can be beneficial? It would be great if you can list pros and cons.

@zhuxiujia
Copy link
Author

Would you please add some detail about the scenario where dependency injection can be beneficial? It would be great if you can list pros and cons.

  • use dependency injection Reduce coupling

  • Unified management struct, For example, I want to count all the http api that I use. just call actix.beans() get All struct, You can do some automated scanning task or job(Very useful for reducing manual coding effort, just like java spring swagger UI scan your http API,auto create Doc )

  • for cons, The downside is that the configuration has become complex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants