Optional Dependencies

Feb 27, 2008 at 12:04 AM
By removing NotPresentBehavior, have we lost the ability to define Optional Dependencies through attributes?

Of course, I believe it will be quite straightforward through config as you simply do NOT declare this property as a dependency.

Having symmetry between config and attribute-based declaration is obviously important.

Any thoughts or I'm simply missing something here (again) ?
Feb 27, 2008 at 1:37 AM

francois_tanguay wrote:
By removing NotPresentBehavior, have we lost the ability to define Optional Dependencies through attributes?

Of course, I believe it will be quite straightforward through config as you simply do NOT declare this property as a dependency.

Having symmetry between config and attribute-based declaration is obviously important.

Any thoughts or I'm simply missing something here (again) ?


The thing is, NotPresentBehavior never really worked. All it did was look in the locator, which was only populated when you built something up. So instead of returning null because a dependency wasn't configured, it'd actually return null if you'd never requested that dependency before. Which is just flat-out broken; the result you got depended on the order that things were requested in.

(After today's changes I'm tempted to remove the locator completely. But that's a different discussion.)

Right now, you specify that something should be injected via the dependency attribute. WHAT gets injected is based on the configuration of the container. If you really don't want to give a logger, do .RegisterInstance<ILogger>(null). Not ideal, but we'll get there. :-)

-Chris