-
Notifications
You must be signed in to change notification settings - Fork 152
Open
Labels
Milestone
Description
Code to demonstrate the problem:
public abstract class BaseComponent
{
[Dependency] private ILogger logger { get; set; }
public bool HasLogger => this.logger != null;
}
public class InheritedComponent : BaseComponent { }
public sealed class DependencyAttribute : Attribute { }
class DependencyAttributePropertySelectionBehavior : IPropertySelectionBehavior
{
public bool SelectProperty(Type type, PropertyInfo prop) =>
prop.GetCustomAttributes(typeof(DependencyAttribute)).Any();
}
[TestMethod]
public void Ctor_Always_Succeeds()
{
// Act
var container = new Container();
container.Options.PropertySelectionBehavior = new DependencyAttributePropertySelectionBehavior();
container.Register<InheritedComponent>();
container.Register<ILogger, NullLogger>();
Assert.IsTrue(container.GetInstance<InheritedComponent>().HasLogger);
}The test fails, while the expected behavior is for the property to get injected, because:
- Private properties on the derived class are injected
- This worked in the past and is likely a regression that was introduced in v4.
Fixing this issue, however, should be considered a breaking change, because Simple Injector will start calling SelectProperty on properties that were previously skipped.