views:

124

answers:

2

I'm in the process of writing a DI framework for PHP 5, and I've been trying to find the 'official' definitions of some words in relation to dependency injection. Some of these words are 'context' and 'lifecycle'. And also, what would I call the object that gets created/injected? Finally, what is the difference between components and services, and which term (if either) should I call the objects that can be injected?

I've read Martin Fowler's article and looked through other DI frameworks (Phemto, Spring, Google Guice, Xyster, etc.), but I want to know what you think. Thanks!

+1  A: 

I don't know that there's an 'official' definition. Fowler's article was the first piece that I read on DI. If that's not authoritative enough for you, I don't see how SO will improve on that.

What does 'looked through' mean to you? How much of the documentation have you read? Have you tried writing any applications with it? You've already done a pretty good job of investigating this for yourself if you've written code with Spring and Guice. If you've just read a few articles that Google brought back you've got more to do.

'Context' in Spring means the factory used to instantiate objects for you. I usually have one per application or web app. My application is usually the 'context' in which objects are created.

'lifecycle' is no different for DI - it has to do with when an object is created, initialized, used, and destroyed.

Components are data and operations in a single software artifact. Services are special kinds of components that perform business-significant operations, usually distributed on a network. Services are usually components, but not all components are services. They aren't synonyms.

You can write components or services without a DI framework. If it helps you to call injected objects 'components', be my guest.

I'm curious: why the emphasis on names for these things? Naming is certainly important, but it's not the primary issue with DI.

duffymo
I understand the basis of dependency injection, but I want to use the terms correctly for my implementation of DI
I don't know of a universally "correct", precise terminology. Why do you think it matters so much? Do you think the Spring folks have suffered because their definitions are't official enough? It's a bike shed argument waiting to happen, IMO.
duffymo
It's more curiosity than anything else, I didn't think it that big of a deal to ask for others' opinions on it.
+2  A: 

Dependency Injection (DI) in computer programming refers to the process of supplying an external dependency to a software component. It is a specific form of inversion of control where the concern being inverted is the process of obtaining the needed dependency.

  • lifecycle : singleton, per-request, transient .... how long should live in container
  • components : A simpler definition can be: A component is an object written to a specification. It does not matter what the specification is: COM, Enterprise JavaBeans, etc., as long as the object adheres to the specification.
  • services : The term service refers to a discretely defined set of contiguous and autonomous business or technical functionality.
  • context : the separation at the container level of the provided implementations to the consumers. Example is the that golden partners on green pages will have 15% discount for red socks.

have fun :)

ruslander
Thanks, that's exactly what I was looking for!