import run from 'ember-metal/run_loop';
import { get } from 'ember-metal/property_get';
import { Mixin } from 'ember-metal/mixin';

export default Mixin.create({
  /**
   The container stores state.

   @private
   @property {Ember.Container} __container__
   */
  __container__: null,

  /**
   Given a fullName return a corresponding instance.

   The default behaviour is for lookup to return a singleton instance.
   The singleton is scoped to the container, allowing multiple containers
   to all have their own locally scoped singletons.

   ```javascript
   var registry = new Registry();
   var container = registry.container();

   registry.register('api:twitter', Twitter);

   var twitter = container.lookup('api:twitter');

   twitter instanceof Twitter; // => true

   // by default the container will return singletons
   var twitter2 = container.lookup('api:twitter');
   twitter2 instanceof Twitter; // => true

   twitter === twitter2; //=> true
   ```

   If singletons are not wanted an optional flag can be provided at lookup.

   ```javascript
   var registry = new Registry();
   var container = registry.container();

   registry.register('api:twitter', Twitter);

   var twitter = container.lookup('api:twitter', { singleton: false });
   var twitter2 = container.lookup('api:twitter', { singleton: false });

   twitter === twitter2; //=> false
   ```

   @public
   @method lookup
   @param {String} fullName
   @param {Object} options
   @return {any}
   */
  lookup: containerAlias('lookup'),

  /**
   Given a fullName return the corresponding factory.

   @public
   @method lookupFactory
   @param {String} fullName
   @return {any}
   */
  lookupFactory: containerAlias('lookupFactory'),

  /**
   @private
   */
  willDestroy() {
    this._super(...arguments);

    if (this.__container__) {
      run(this.__container__, 'destroy');
    }
  }
});

function containerAlias(name) {
  return function () {
    var container = get(this, '__container__');
    return container[name](...arguments);
  };
}

@@ -1577,29 +1577,30 @@
 tory.%0A%0A   @p
-ublic
+rivate
 %0A   @method 

Mark `ContainerProxy#lookupFactory` private.