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); }
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); }
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); }
void IInjector.Inject(ReferenceInjection injection) { var value = referenceResolver.GetReferenceFor(injection); injection.Property.SetValue(this, value, null); }