Лучшие практики Внедрения зависимости и антишаблоны

Несколько вещей, которые укусили меня:

  • :main: - RDoc использует только последний оцененный; лучше всего для проверки существует только один в проекте, и Вы также не используете --main параметр командной строки.
  • то же как предыдущее, но для :title:
  • :section: не работает очень хорошо
31
задан ripper234 5 November 2009 в 18:21
поделиться

5 ответов

I really enjoyed this article regarding DI, as it's targeted towards people who don't have a ton of DI experience, or don't even know what it is.

https://mtaulty.com/2009/08/10/m_11554/

What’s Unity?

It’s a “dependency injection container”.

Now, at that point a bunch of folks reading this will say “Yes, we know and we’re already using it for reasons A, B, C or we’ve elected not to use it for reasons X,Y,Z ” and I imagine a bunch of other folks might say;

“Huh? What’s a dependency injection container?”

This post is for the latter people – it’s not meant to be exhaustive but hopefully it’s not completely unhelpful either :-)

9
ответ дан 27 November 2019 в 22:51
поделиться

На мой взгляд, книгу Дханджи Прасанны Dependency Injection необходимо прочитать разработчикам программного обеспечения, как новичкам, так и экспертам. Он занимается непосредственно вашими вопросами DI.

3
ответ дан 27 November 2019 в 22:51
поделиться

В руководстве пользователя Guice есть раздел с рекомендациями. .

3
ответ дан 27 November 2019 в 22:51
поделиться

Я обнаружил, что когда я вижу нарушение Закона Деметры , это намек на то, что мне может потребоваться внедрение зависимости.

Например:

void doit()
{
    i += object.anotherobject.addvalue; //violation of Law of Demeter
}

Иногда намекает, что я могу захотеть внедрить в зависимость другой объект .

1
ответ дан 27 November 2019 в 22:51
поделиться

My basic rule about when to use DI is that I will inject between layers, so between my controller and the dao would be a layer, so I can inject, so that if I want to mock out a layer I can.

I think using DI within the same layer is not a good idea mainly because the layer should be tightly coupled, as they are related, unless you have a user story that makes it useful.

For example, if your DAO is may be on separate computers then you may need to be able to pretend that they are one layer, but use DI to actually switch between all on one machine and separate machines. Then the developer can do everything on one machine and it should work on separate machines.

But, unless there is some pressing need, I think DI within the same layer is an unnecessary complication.

0
ответ дан 27 November 2019 в 22:51
поделиться
Другие вопросы по тегам:

Похожие вопросы: