Example #1
0
        public TConfiguration Create <TConfiguration>()
        {
            _scopedObjects = new Dictionary <Type, object>();
            var configurationType = typeof(TConfiguration);

            if (_configuration.IsConfigured(configurationType))
            {
                var injectionSpecification = _configuration.GetInjectionSpecification(configurationType);
                return((TConfiguration)Create(injectionSpecification));
            }
            throw new ArgumentException($"Type is not configured: ${typeof(TConfiguration)}");
        }
Example #2
0
        public void GivenCreate_WhenConfigurationStyleIsNone_ThenCreatesClass()
        {
            var configurationType = typeof(IBasicClass);
            var injection         = new InjectionSpecification
            {
                ConfigurationType  = configurationType,
                ConfigurationStyle = ConfigurationStyle.None
            };

            A.CallTo(() => _mockConfiguration.IsConfigured(configurationType)).Returns(true);
            A.CallTo(() => _mockConfiguration.GetInjectionSpecification(configurationType)).Returns(injection);

            var dependencyInjector = new DependencyInjector(_mockConfiguration);

            Assert.Throws <ArgumentException>(() => dependencyInjector.Create <IBasicClass>());
        }
        public void GivenConfigureTransient_WhenConfigurationIsDoubleSpecified_ThenReturnsLastSpecification()
        {
            var configurationType = typeof(IBasicClass);

            _target.ConfigureTransient <IBasicClass, BasicClass>();
            _target.ConfigureTransient <IBasicClass, ASecondBasicClass>();

            var specification = _target.GetInjectionSpecification(configurationType);

            Assert.NotNull(specification);
            Assert.AreEqual(typeof(IBasicClass), specification.ConfigurationType);
            Assert.AreEqual(typeof(ASecondBasicClass), specification.SpecificationType);
            Assert.AreEqual(ConfigurationScope.Transient, specification.ConfigurationScope);
        }