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

Yii 2.0 will be with dependency injection? #814

Closed
gitmastro opened this issue Jun 12, 2012 · 20 comments
Closed

Yii 2.0 will be with dependency injection? #814

gitmastro opened this issue Jun 12, 2012 · 20 comments

Comments

@gitmastro
Copy link

Like We have seen other frameworks are coming with 'dependency injection' feature. so in Yii 2.0 we should have ,.,

@qiangxue
Copy link
Member

No, we support a feature not because other frameworks support it, but because we need it in real life.

@samdark
Copy link
Member

samdark commented Jun 12, 2012

Please use http://www.yiiframework.com/forum/index.php/forum/42-design-discussions-for-yii-20/ for design discussions about Yii2.

@gitmastro
Copy link
Author

Thanks @qiangxue and @samdark for quick response..

@soggie
Copy link

soggie commented Nov 1, 2012

Is there any reason why you would think Dependency Injection is not something that's used in real life? In my experiences, it's crucial to create testable and self-contained classes, and ease the process of mocking dependencies for classes.

@samdark
Copy link
Member

samdark commented Nov 1, 2012

@soggie even 1.1 has DI. Yii is a practical framework, not something you use because it has all these fancy patterns and stuff. We're just not emphasizing on patterns, that's it.

@resurtm
Copy link
Contributor

resurtm commented Nov 1, 2012

@soggie, and yes, Yii's approach isn't less testable and less maintainable. Take a look at the existing unit tests of the framework if you want real examples of replacing components in the testing environment.

@soggie
Copy link

soggie commented Nov 1, 2012

Well, not trying to start any arguments here. I use DI myself, and feel that it's a wonderful pattern with plenty of real world applications (in fact, our current production system uses a somewhat homemade DI container), so I was wondering as to why you would think DI is not something anybody needs in real life. Just hoping for a more detailed explanation as to the design decision not to include DI, that's all. :)

I haven't gone through the code of Yii, and I'll probably take a deeper dive tonight.

@samdark
Copy link
Member

samdark commented Nov 1, 2012

@soggie DI is a good pattern and DI is there in Yii 1.1. Besides that many classical patterns are used in Yii we don't think it worth emphasizing it like "here we're using DI and here we're using a factory and there's the registry".

@creocoder
Copy link
Contributor

@samdark I'm totally agree with you, but why not emphasizing at least for avoid some excess questions and from political point of view?

@samdark
Copy link
Member

samdark commented Nov 1, 2012

Because it complicates things for newbies a lot. When emphasizing on patterns you're actually emphasizing on "how" instead of "what".

@intel352
Copy link
Contributor

@samdark, agreed it's excessive for newbies, but it would be nice to have one or more articles that cover some of the more prominent features of Yii, including the [anti-]patterns used (and why?, such as what advantages the approach provides), along with links to more advanced reading (such as Martin Fowler's explanation of DI).

I've worked fairly extensively with Yii 1.1 for various projects, and mimicked & used the patterns I've found in Yii within my own code, but I didn't know until tonight that one such pattern was Dependency Injection. So that means while I've had practical knowledge regarding the implementation & usage, I would've had no clue what was being referred to (without a notable explanation) if a colleague were to bring up Dependency Injection or Inversion of Control.

So at least having an area to further educate on such patterns (or at least reference explanatory links) would be quite helpful for other Yii developers.

@samdark
Copy link
Member

samdark commented Jan 14, 2013

Yep, maybe a set of wiki articles will be suitable for it. Will consider writing some later.

@grikdotnet
Copy link

The only features Qiang uses are the ones he can teach other to :)
Yii 1 has DI in the form of shared application components, an application serves as a dependency injection container. It does not have a way to create multiple custom IoC containers, tools for interface injection or component dependency like, e.g. Symfony, and that works well for small projects. If you need a container in your project, you can easily take the one from Symfony.

@cebe
Copy link
Member

cebe commented Sep 8, 2013

I'm totally agree with you, but why not emphasizing at least for avoid some excess questions and from political point of view?

@creocoder Would you like Yii::app() get renamed to Yii::appIamTheDIContainerHere()? :)

@samdark
Copy link
Member

samdark commented Sep 8, 2013

I'm strongly against it.

@creocoder
Copy link
Contributor

@cebe Ofcourse not. I mean another things, mostly docs ;)

@rankovski
Copy link

I found this thread while searching how to use DI in Yii controller. Here is my post on the forum, so if anyone can answer it, it will be great: http://www.yiiframework.com/forum/index.php/topic/52810-using-interfaces-and-di-in-yii-controllers/

@agussuhartono
Copy link

I think, Yii have IoC only on Application Object, used to manage component.
But, it's not DI, I's Service Locator

@cebe
Copy link
Member

cebe commented May 16, 2015

@agussuhartono
Copy link

wow, great news for me, thanks @cebe

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