Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4006944
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:34:28+00:00 2026-05-20T08:34:28+00:00

The system I’m working on is using something like a dynamic router + dep.injection

  • 0

The system I’m working on is using something like a dynamic router + dep.injection pattern, specifically:

  1. A router object uses config to instantiate module objects. Modules are independent and may be many.
  2. An instance of the router object is dependency-injected into module constructor and is used as an API reference/pointer (probably irrelevant for the question, but is here for clarity sakes)
  3. modules use API to add rules that link input patterns to specific module methods
  4. Router receives input, checks it against the rule set and calls module methods that match
  5. Results are collected by the router and passed over to output processor

Module contructor:

class module {
    public function __construct(&$router) {
        $router->addRoute('some-input-pattern', array($this, 'someMethod'));
    }

    public function someMethod() {
         return 'some arbitrary result';
    }
}

However simple this may seem, there are cases when module and router need to communicate about something not related to arbitrary return values.

For instance, there are occasions when a module has to trigger an event, or an exception, that would have to be handled by the module itself. It can originate in any module method, and has to be handled by a specific one. (Having tons of try/catch blocks in every method doesn’t seem right, and the only ‘entry point’ that can handle any exception is outside of the module, and in the router. Module throws, module handles, but only router can actually catch. Sounds wrong.)

class module {
    public function __construct(&$router) {
        ...
        $router->addExceptionHandler('dbTableNotFoundException', 
                                     array($this, 'installSchema'));
    }
 }

On other occasions there are events that need to be handled by the router itself. For example, module can request that the router proceeds as if it has received a special type of input, ignoring the real one. The router then has to recheck it against the rule set, and call appropriate methods.

   public function someMethod(){
         ...
         throw routerRestartException('special-input');
   }

On other occasions events may require no handling other than passing them through to output, such as human-eyes-only errors.

   public function someMethod(){
         ...
         throw humanEyesException("You can't do that!");
   }

This effectively leads me to thinking of two communication aspects, because router and modules exchange both arbitrary return data and special control messages.

So far the system control messages aspect is implemented by modules throwing exceptions, and the router catching. This requires that modules register two types of methods — one for processing input, and another for handling exceptions, which is probably smelly.

Some of the exceptions seem to affect flow control, and I believe using exceptions for that isn’t a good practice either.

The question stands, is there a best practice or a pattern for building this kind of two-aspect communication between router object and its dependent modules?

EDIT

A thought along the way: one way of improving the situation by detaching in-module exception handling from the router could be using Observer pattern for custom Exceptions:

public function __construct(&$router){
    ...
    dbTableNotFoundException::addObserver(array($this, 'installSchema'));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T08:34:28+00:00Added an answer on May 20, 2026 at 8:34 am

    For letting modules react upon other modules and API events I would use the Observer pattern. Your API can provide several observable subjects (those can be classes be the API could provide un/register and notify procedures for each observable subjects)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The system I am currently working on requires some role-based security, which is well
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace GenericCount { class Program {
System.IO.Directory.GetFiles() returns a string[] . What is the default sort order for the returned
System.IO.BinaryReader reads values in a little-endian format. I have a C# application connecting to
System.Drawing.Color objects apparently won't serialize with XmlSerializer. What is the best way to xml
Are System.IO.Compression.GZipStream or System.IO.Compression.Deflate compatible with zlib compression?
The System.Windows.Threading.DispatcherObject class (which DependencyObject is based on) contains a useful function, called CheckAccess()
The system I work on here was written before .net 2.0 and didn't have
The System.Diagnostics.EventLog class provides a way to interact with a windows event log. I
Our system dynamically generates a large report by converting many HTML pages into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.