IoC, AOP and more
Asked Answered
A

3

12

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?

What is Spring.net/ninject with respect to IoC and AOP?

Anthelion answered 3/6, 2009 at 17:41 Comment(1)
also check this: #15675831Cheremkhovo
K
4

JMSA,

James Kovacs wrote a fantastic article which covers many of your questions I would recommend reading it Here

Spring.Net, Ninject, Unity, Castle Windsor, Autofac are all IOC containers which are configurable in different ways, many of them do also support AOP.

Frameworks for IOC/DI are useful because they provide standard mechanisms, for example if you are hiring a new developer it is much easier to say, we use this framework and pass them the links to the tutorials / help guide. At the same time these frameworks are tried and tested by a large community / companies.

Let me know if any of your questions remain unanswered after reading the article and the above answes and I'll do my best to provide further assistance.

Kuwait answered 3/6, 2009 at 18:12 Comment(4)
Is there any relationship between IoC/DI and AOP?Badger
To some degree there is a relationship there. If you look into AOP it mostly gets applied for things like Logging, and Security permissions style of cross cutting concerns. In the case of logging a lot of developers would use that along with DI / IOC so that they could switch logging providers (say swap log4net to enterprise library logging). But the true answer is you don't need DI or IoC to implement AOP and to implement DI or IoC you don't need to use AOP.Kuwait
The Microsoft Unity container does use both aop and DI to specify dependencies. For example if you had a dll that had services and one that had data access code you could specify that the service dll depends on the data access dll and therefore instruct unity to load the data access dll and initialize it before attempting to initialize the services dll.Kuwait
Another flavour of DI / IoC is using a Service locator pattern. you may want to research this also. Martin Fowlers blog has a lot on this topic. toolkit has linked to his blog below.Kuwait
S
3

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.

Solstice answered 3/6, 2009 at 17:42 Comment(0)
M
2

Martin Fowler has a good article here on the meaning of Inversion of Control and Dependency Injection.

Spring.NET usage AOP is described in detail here. I'm more familiar with the Java-based version of Spring, so I cannot say with absolutely certainty that Spring.NET currently only supports proxy-based AOP.

That is, a class to be advised must implement an interface. Spring will create a dynamic proxy that implements this interface and delegates to the original target instance.

Although it does state:

In a future release we will implement proxies using inheritance, which will allow you to proxy classes without interfaces as well and will remove some of the remaining raw reference issues that cannot be solved using composition-based proxies.

Meridith answered 3/6, 2009 at 18:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.