public void SetProviderChangesTheProvider()
        {
            SingletonProvider provider1 = new SingletonProvider(typeof(Clazz), injector);
            TypeProvider      provider2 = new TypeProvider(typeof(Clazz));
            InjectionMapping  config    = new InjectionMapping(injector, new MappingId(typeof(Clazz), null));

            config.ToProvider(provider1);
            Assert.AreEqual(config.GetProvider(), provider1);
            config.ToProvider(null);
            config.ToProvider(provider2);
            Assert.AreEqual(config.GetProvider(), provider2);
        }
        public void InjectionMappingAsSingletonMethodCreatesSingletonProvider()
        {
            InjectionMapping config = new InjectionMapping(injector, new MappingId(typeof(Clazz), null));

            config.AsSingleton();
            Assert.IsInstanceOf <SingletonProvider>(config.GetProvider());
        }
        public object Apply(Type targetType, Injector activeInjector, Dictionary <string, object> injectParameters)
        {
            object instance = _otherMapping.GetProvider().Apply(targetType, activeInjector, injectParameters);

            if (_postApply != null)
            {
                _postApply(this, instance);
            }
            return(instance);
        }
Beispiel #4
0
        /*============================================================================*/
        /* Private Functions                                                          */
        /*============================================================================*/

        private void PostMappingChange(MappingId mappingId, InjectionMapping mapping)
        {
            DependencyProvider dp = mapping.GetProvider();

            if (dp is SingletonProvider)
            {
                dp.PostApply += HandlePostApply;
                _dependencyMappingIds [dp] = mappingId;
            }
            else if (dp is ValueProvider)
            {
                AddSingleton(mappingId, _injector.GetInstance(mappingId.type, mappingId.key));
            }
        }
        public void MappingWithoutProviderEverSetUsesClassProvider()
        {
            InjectionMapping config = new InjectionMapping(injector, new MappingId(typeof(Clazz), null));

            Assert.IsInstanceOf <TypeProvider>(config.GetProvider());
        }
		/*============================================================================*/
		/* Private Functions                                                          */
		/*============================================================================*/
		
		private void PostMappingChange (MappingId mappingId, InjectionMapping mapping)
		{
			DependencyProvider dp = mapping.GetProvider ();
			if (dp is SingletonProvider) 
			{
				dp.PostApply += HandlePostApply;
				_dependencyMappingIds [dp] = mappingId;
			} 
			else if (dp is ValueProvider) 
			{
				AddSingleton(mappingId, _injector.GetInstance(mappingId.type, mappingId.key));
			}
		}