public void UsesDelegatePassedIn() { var finder = new DelegatePropertySelector((propInfo, instance) => { return(propInfo.GetCustomAttributes <InjectPropertyAttribute>().Any()); }); foreach (var propInfo in typeof(HasProperties).GetProperties()) { var expected = propInfo.GetCustomAttributes <InjectPropertyAttribute>().Any(); Assert.Equal(expected, finder.InjectProperty(propInfo, null)); } }
public void UsesDelegatePassedIn() { var finder = new DelegatePropertySelector((propInfo, instance) => { return propInfo.GetCustomAttributes<InjectPropertyAttribute>().Any(); }); foreach (var propInfo in typeof(HasProperties).GetProperties()) { var expected = propInfo.GetCustomAttributes<InjectPropertyAttribute>().Any(); Assert.Equal(expected, finder.InjectProperty(propInfo, null)); } }
private static ContainerBuilder GetConfiguredBuilder() { var builder = new ContainerBuilder(); // Is the property marked with [InjectProperty], and is it null? IsPropertyMarked = new DelegatePropertySelector((pi, obj) => { var shouldInject = pi.CustomAttributes.Any( cad => cad.AttributeType.Name == nameof(InjectPropertyAttribute) ) && pi.GetValue(obj) == null; return(shouldInject); }); // As each instance/type is activated, also inject marked properties. builder.RegisterCallback(crb => { crb.Registered += (_, regdArgs) => { regdArgs.ComponentRegistration.Activated += (_, actdArgs) => actdArgs.Context.InjectProperties(actdArgs.Instance, IsPropertyMarked); }; }); return(builder); }