SingletonLazyCreator AddCreator(SingletonId id)
        {
            SingletonLazyCreator creator;

            if (!_creators.TryGetValue(id, out creator))
            {
                creator = new SingletonLazyCreator(_container, this, id);
                _creators.Add(id, creator);
            }

            creator.IncRefCount();
            return(creator);
        }
Exemple #2
0
        SingletonLazyCreator AddCreator <TConcrete>(Func <DiContainer, TConcrete> method)
        {
            SingletonLazyCreator creator;

            var id = new SingletonId(typeof(TConcrete));

            if (_creators.ContainsKey(id))
            {
                throw new ZenjectBindException(
                          "Found multiple singleton instances bound to type '{0}'".With(typeof(TConcrete)));
            }

            creator = new SingletonLazyCreator(
                _container, this, id, (container) => method(container));

            _creators.Add(id, creator);

            creator.IncRefCount();
            return(creator);
        }
        SingletonLazyCreator AddCreatorFromMethod <TConcrete>(
            string identifier, Func <InjectContext, TConcrete> method)
        {
            SingletonLazyCreator creator;

            var id = new SingletonId(identifier, typeof(TConcrete));

            if (_creators.ContainsKey(id))
            {
                throw new ZenjectBindException(
                          "Found multiple singleton instances bound to type '{0}'".Fmt(typeof(TConcrete)));
            }

            creator = new SingletonLazyCreator(
                _container, this, id, (context) => method(context));

            _creators.Add(id, creator);

            creator.IncRefCount();
            return(creator);
        }
 public SingletonProvider(
     DiContainer container, SingletonLazyCreator creator)
 {
     _creator   = creator;
     _container = container;
 }
 public SingletonProvider(
     DiContainer container, SingletonLazyCreator creator)
 {
     _creator = creator;
     _container = container;
 }