public ProviderBase CreateProvider(Type concreteType, object instance) { Assert.That(instance == null || instance.GetType() == concreteType); SingletonLazyCreator creator; if (!_creators.TryGetValue(concreteType, out creator)) { creator = new SingletonLazyCreator(_container, this, concreteType); _creators.Add(concreteType, creator); } if (instance != null) { if (creator.HasCreatedInstance()) { throw new ZenjectBindException("Found multiple singleton instances bound to the type '{0}'".With(concreteType.Name())); } creator.SetInstance(instance); } creator.IncRefCount(); return(new SingletonProvider(_container, creator)); }
SingletonLazyCreator AddCreator(Type concreteType) { SingletonLazyCreator creator; if (!_creators.TryGetValue(concreteType, out creator)) { creator = new SingletonLazyCreator(_container, this, concreteType); _creators.Add(concreteType, creator); } creator.IncRefCount(); return(creator); }
SingletonLazyCreator AddCreator <TConcrete>(Func <DiContainer, TConcrete> method) { SingletonLazyCreator creator; if (_creators.ContainsKey(typeof(TConcrete))) { throw new ZenjectBindException( "Found multiple singleton instances bound to type '{0}'".With(typeof(TConcrete))); } creator = new SingletonLazyCreator( _container, this, typeof(TConcrete), (container) => method(container)); _creators.Add(typeof(TConcrete), creator); creator.IncRefCount(); return(creator); }
public SingletonProvider( DiContainer container, SingletonLazyCreator creator) { _creator = creator; _container = container; }