Ticket #97 (closed enhancement: fixed)

Opened 2 years ago

Last modified 2 years ago

Give injection provider more informations about requested injection

Reported by: mikey Owned by: mikey
Priority: major Milestone: 0.6.0
Component: InversionOfControl Version: SVN-trunk
Keywords: Cc:

Description

I would like to have more information available inside an injection provider to allow the provider to decide which implementation (or concrete instance) to return. Consider the following:

$binder->bind('stubDatabaseConnection')->named('downloads')->toProvider(new DatabaseConnectionProvider('downloads'));
$binder->bind('stubDatabaseConnection')->named('press')->toProvider(new DatabaseConnectionProvider('press'));
$binder->bind('stubDatabaseConnection')->named('jobs')->toProvider(new DatabaseConnectionProvider('jobs'));

In this example you need several provider instances, one for each named injection. If the provider would know itself about the named annotation it could decide itself what to return. This would keep the amount of bindings lower, and one would only need one provider instance instead of several ones.

Change History

Changed 2 years ago by schst

  • status changed from new to assigned
  • milestone set to 0.4.0

Changed 2 years ago by mikey

  • milestone changed from 0.4.0 to 0.5.0

Changed 2 years ago by mikey

  • milestone changed from 0.5.0 to 0.6.0

Changed 2 years ago by mikey

  • owner changed from schst to mikey
  • status changed from assigned to new

Changed 2 years ago by mikey

  • status changed from new to assigned

Changed 2 years ago by mikey

Some thoughts for the refactoring:

- Scopes and bindings only return injection providers instead of concrete instances to inject. - Injector gets instance from injection provider, which in turn it gets from the binding.

Changed 2 years ago by mikey

Implemented with r1370.

Todo: Increase test coverage, not all use cases are covered. Todo: Update documentation.

Changed 2 years ago by mikey

  • status changed from assigned to closed
  • resolution set to fixed

Test cases added with r1371, documentation was updated as well.

Note: See TracTickets for help on using tickets.