[Nitro] Singletons

Malte Milatz malte at gmx-topmail.de
Mon Feb 5 12:48:27 EST 2007


transfire at gmail.com:
> I'd like to discuss this. How can be accomplished easily? I've been
> thinking about it. Lets say we start off with:
> 
>   my_nitro_app = Nitro::Application.new( ... )
> 
> So now when I define other elements of my app, say a controller, or
> module, how do they get tied into this instance?

A controller could e. g. be tied like this:

	my_nitro_app.mount('/' => MyController)

This may be delegated to my_nitro_app.server.mount, i.e. the method that
really does the work would be Nitro::Server#mount. I'm looking forward
for further examples of how such an API may look.

It means basically that functionality is moved from global constants (in
this case, Nitro::Server) to instances that do not have to be globally
accessible. As I understand it, this would be a total redesign of Nitro,
and I'm not sure whether that will be a good thing. The example shows,
though, that Dependency Injection / Inversion of Control is nothing
complicated per se. The point is simply that you have mainly instance
methods, as opposed to having mainly Module methods.

Regards, Malte



More information about the Nitro-general mailing list