AngularJs: Double Injectors !!

When createInjector is called to load modules, there are two injectors created they are providerInjector & instanceInjector, createInjector will return instanceInjector method. Lets look at the implementationinjectorsTwo parameters are passed into createInternalInjector method cache and factory function. Cache is used for lookup and factory function is used to instantiate service when not found in cache.

InstanceInjector: It stores the list of instantiated services, whereas cacheInjector stores the list of uninstantiated services. When createInternalInjector is called the second parameter passed is a factory function. It will try to get the service by appending ‘provider’ suffix and then invokes the $get function on provider and returns the result.

providerInjector: cache for providerInjector is initialized with one service $provider. It is through this service that all other services are registered. Details of provider implementation are present here.

Now that we understood how createInjector will resolve dependencies,. Let’s see how it loads modules in the next post.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s