[Nitro] Singletons

George Moschovitis george.moschovitis at gmail.com
Sun Feb 4 15:33:51 EST 2007


Ok this is nice. But really, a Nitro application needs *one* Server and
*one* Dispatcher.

-g.

On 2/4/07, transfire at gmail.com <transfire at gmail.com> wrote:
>
>
>
> On Feb 4, 1:33 pm, transf... at gmail.com wrote:
> > On Feb 4, 12:23 pm, "George Moschovitis"
> >
> > <george.moschovi... at gmail.com> wrote:
> > > >  http://onestepback.org/index.cgi/Tech/Ruby/
> > > > DependencyInjectionInRuby.rdoc
> >
> > > I don't really want to add DI, IOC etc to Nitro. I would like to
> simplify
> > > Nitro and make it more accessible not include the most advanced
> concepts...
> > > What do others think?
> >
> > Simple is good. I wouldn't want it if it's not so. Here's just a rough
> > concept, maybe this can give you more of a concrete idea of how it
> > could work and not be complex:
> >
> >   class Class
> >     def needs *a
> >       (@needs ||= []).concat(a.flatten.collect{|e|e.to_sym})
> >     end
> >     def need?(name)
> >       @needs.include?(name.to_sym)
> >     end
> >   end
> >
> >   def Nitro.inject( services )
> >     ObjectSpace.each_object(Class) do |k|
> >       if k.needs?(:server)
> >         k.class_eval do
> >           define_method{:server){ services[:server] }
> >         end
> >       end
> >     end
> >   end
> >
> >   my_server = Nitro::Server.new
> >
> >   Nitro.inject( :server => my_server )
> >
> >  class Nitro::Element
> >    needs :server
> >  end
>
> Hmm... I guess that is too complex. b/c why not just:
>
>   $services = {}
>
>   class Class
>     def needs(name)
>       define_method(name){ $services[name] }
>     end
>   end
>
>   class Nitro::Element
>     needs :server
>   end
>
>   my_server = Nitro::Server.new
>
>   $services[:server] = my_server
>
> Okay, i'll shut up now... ;-)
>
> T.
>
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
>



-- 
http://blog.gmosx.com
http://cull.gr
http://www.joy.gr
http://nitroproject.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/nitro-general/attachments/20070204/ffd7be92/attachment.html 


More information about the Nitro-general mailing list