开发者

Overuse of "service" classes when using DI containers?

I'm beginning to learn about to how to use DI containers. I'm finding myself using a lot of "service" classes (e.g. ParsingService) with a few dependencies injected.

开发者_JS百科

Is it possible that I'm overusing service classes if that's what I gravitate towards whenever I need a central place to consume several dependencies?

Thank you.


Often, you can use Constructor Injection instead of "Services" to accomplish the same, or similar goals. This also often has many advantages, and is more in line with many IoC container goals.

I'd recommend Martin Fowler's article on the subject, particularly his section Service Locator vs Dependency Injection. He discusses the advantages of both approaches.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜