mariocasciaro / scatter

IoC container and out-of-the-box extensibility for Node.js applications
MIT License
154 stars 14 forks source link

In depth example #24

Open newmanw opened 10 years ago

newmanw commented 10 years ago

First of all thanks, without people like you I could not stand on the shoulders of giants. That being say a lot of the guide and docs are over my head. You make huge leaps and much of what you are doing looks like 'magic' that I don't understand. I took a look at your example and it was too simple and does not prove a real problem. At least for me, and maybe betting many others a full example with something like express and mongoose would be crazy helpful in understanding how to get started with scatter.

A simple case: Given a couple routes access a couple models. Bonus would be a plugin that had access to the models.

Also what about node modules? Should they be injected? Or is require always the right answer for those?

mariocasciaro commented 10 years ago

Hi Billy, thanks for asking this, actually you are right I found the time to create a proper example with an in depth explanation, right now it's all left out to the user to figure out how to use Scatter with the help of the API docs and the guide. I'll try to find some time to create a nice example, in the meanwhile you may want to just ask here any doubt you have or take a look at Particles and Hadron which are based on Scatter, it will sure help to understand how to use Scatter in a real project.

For the question around modules, the answer is: it depends. Usually you may want to use libraries as you always have done by using require while leaving to Scatter all the code that is "application". There are some edge cases where you still may want to load npm modules using the npm! loader instead of require, to make sure that all the particles share the same instance of the module.

newmanw commented 10 years ago

@mariocasciaro I have a better idea. Instead of talking on the rather huge task of implementing scatter into my existing project I thought it might be a better idea to play with it on a smaller scale. All while trying to prove my application would be better with scatter. In the next week or so I am going to try and tackle creating a simple application that uses scatter to define a few services shared across the core of the app and plugins. My interests lie in the MEAN stack, but figure its mainstream enough that it should help others.

Plans:

  1. Implement a few core routes in Express and initialize them dynamically
  2. Routes will write to a simple mongo collection and depend on a mongoose 'model'
  3. Throw in a couple simple core views in AngularJS to visualize the data.
  4. Add a couple plugins that get 'installed' dynamically by scatter (includes Express routes and AngularJS view). Plugins will shared some core modules as well as add there own models and views

Once done I can share the code with you to see if its something you might want to start with for an example project. In this way I can learn Scatter and maybe save you from writing the example.

If I hit any roadblocks I post questions here if that is ok. At least to document parts that were confusing to me, who knows someone else may have the same troubles.

mariocasciaro commented 10 years ago

Hey Billy, I think that's a great idea, let me know if you need anything or if I can help you with making any design choice. I'm glad to help.

schuimer commented 9 years ago

@mariocasciaro , Mario, thank you for this great work! It seems to be exactly what I need for my current project! Like Billy, I am also looking for an in-depth example of scatter with expressjs and mongoose. @newmanw , Billy, were you able to create a simple sample application based on scatter and mean stack? If yes, I would be very interested..thank you very, very much!!!

BinaryWorrier commented 9 years ago

I can definitely second this, can't get simple "Service" sample working . . . https://stackoverflow.com/questions/27315814/need-help-getting-scatter-ioc-services-working

mariocasciaro commented 9 years ago

http://stackoverflow.com/a/27318006/1234037