示例#1
0
        public void ShouldSetReference()
        {
            var dependency = new ServiceDependency();

            objectFactory.Expect(x => x.GetObject("test")).Return(dependency);

            var property  = typeof(TestClass).GetProperty("StaticDependency");
            var reference = new ReferenceInjection(property, "test");

            injector.Inject(new[] { reference });

            Assert.AreEqual(dependency, TestClass.StaticDependency);
        }
示例#2
0
        private ReferenceInjection GetOrCreateReference(PropertyInfo property)
        {
            var injection = Lemming.Injections
                            .OfType <ReferenceInjection>()
                            .SingleOrDefault(x => x.Property == property);

            if (injection == null)
            {
                injection = new ReferenceInjection(property);
                Lemming.Inject(injection);
            }

            return(injection);
        }
示例#3
0
        public object GetReferenceFor(ReferenceInjection injection)
        {
            object value = null;

            if (!string.IsNullOrWhiteSpace(injection.ReferencedLemming))
            {
                value = objectFactory.GetObject(injection.ReferencedLemming);
            }

            if (value == null)
            {
                value = objectFactory.GetObject(injection.Property.PropertyType);
            }

            return(value);
        }
示例#4
0
        void IInjector.Inject(ReferenceInjection injection)
        {
            var value = referenceResolver.GetReferenceFor(injection);

            injection.Property.SetValue(this, value, null);
        }