IoC, AOP and more

前端 未结 3 825
难免孤独
难免孤独 2020-12-29 10:42

What is an IoC container?

What is an IoC/DI framework?

Why do we need a framework for IoC/DI?

Is there any relationship between IoC/DI and AOP?

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-29 10:59

    From a semantics point of view...

    Dependency Injection itself implies a dependency, i.e. something that is required for construction/use (the application's "core concerns"). For example, a car is not a car without an engine.

    Aspects are described as being cross-cutting to the application's core concerns. That means both separate from and non-crucial to the core concerns (you could think of them as "nice-to-haves"). Since the application can run without aspects, are they really dependencies? For example, a car is still a car even without an immobiliser.

    (Of course, this is from a theoretical standpoint. In the real world matters like security are often as crucial to the existence of a marketable product as the core concerns themselves.)

    So in while in practice DI can be used to implement aspects, I would not call that process true DI. This is coming from someone who uses constructor injection exclusively.

提交回复
热议问题