Is there a service container in meteor?

Hi, I’m new on meteor, I came from the Java and it’s popular Spring Framework and Laravel, a PHP framework that it’s growing so fast. Those frameworks provide facilites to use dependency injection using a service container, so you can:

Create a controller

class UserController extends Controller
{
    private service;

    public function construct(MessageService service)
    {
        this.service = service;
    }
   //Send a message via email, SMS, Slack...whatever that's specify in
   //Service Provider
}

And inject the MessageService instance via a Service Provider doing:

serviceProvider.bind('MessageService', function () {
  return new MessageService(app.make('EMailStrategy'));
}); 

This gives tremendous facilities: reduced dependencies, increased testability …

I see also the way that angular-meteor (also angular 2) gives the ability to use dependency injection, but it’s too angularish (although I like angular 2). And other javascript frameworks like http://adonisjs.com/ are now having the Service Container…so I asked: Is there a service container in meteor?

Not specifically in Meteor as far as I am aware of. Most of the current direction is imports based, see for example this:

That being said it’s just javascript so if you can do it in javascript you can likely do this as well.

It looks like there are a lot of them:


Isn’t that the kind of solution you are looking for or does it need any specific integrations with Meteor?

1 Like

For the frontend-part in meteor, there is mantra: https://github.com/kadirahq/mantra

which solves Dependency injection in a very simple, yet powerful way.

If you want to go with component-driven design, mantra is the way to go. It’s designed for component-ui-layers like react.

3 Likes