Feature Requests: Browse | Submit New | Admin

[#15502] Could namespaces that register no custom service implementations be optional?

Date:
2007-11-09 19:10
Priority:
3
Submitted By:
Brian Hartin (bjhartin)
Assigned To:
Nobody (None)
Category:
Core
State:
Open
Summary:
Could namespaces that register no custom service implementations be optional?

Detailed description
Not sure if Needle is still active...we will probably fix this on our own and would be happy to contribute back.

Consider the following situation:

* Namespaces represent customers:

  customer_a
  customer_b
  # ...
  customer_z # 26 customers

* Most customers use the default implementation of most services, i.e. exceptions are rare.

# (In config.rb, or similar)
# 24 customers use the default mailer, only two need something else
registry.register(:mailer) {DefaultMailer.new} # The default
registry.customer_a.register(:mailer) {SpecialMailer.new}
registry.customer_m.register(:mailer) {SpecialMailer.new}

# (In some application code)
def send_bulk_mails(customer)
  mailer = registry[customer][:mailer]
  # ...

The problem is that I still have to register the namespaces for the 24 customers that don't need custom service
implementations, e.g. the following code will fail:

customer = :customer_b
registry[customer][:mailer] # Fails with ServiceNotFound for :customer_b

We actually have several levels of namespaces, e.g customer/project/...  It seems like wasted effort to describe the
entire namespace 'tree' when only a few 'nodes' are actual service implementations.

Am I missing something?

It seems to me like Needle::Container.get could be changed to react differently on ServiceNotFoundException, i.e. checking
the parent.  However, that might be naive...I'll try it and see.

Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
No Files Currently Attached

Changes:

No Changes Have Been Made to This Item