diff --git a/Stylet/StyletIoC.cs b/Stylet/StyletIoC.cs index e51958a..8f42620 100644 --- a/Stylet/StyletIoC.cs +++ b/Stylet/StyletIoC.cs @@ -857,23 +857,20 @@ namespace Stylet var creator = Expression.New(ctor, ctorParams); var assignment = Expression.Assign(instanceVar, creator); - var buildUpExpression = container.GetBuilderUpper(this.Type).GetExpression(container, assignment); + var buildUpExpression = container.GetBuilderUpper(this.Type).GetExpression(container, instanceVar); - Expression completeExpression; - - // If there's no buildUp, avoid creating the block expression after all - it hurts runtime performance - if (buildUpExpression == Expression.Empty()) - { - completeExpression = creator; - } - else - { - var blockItems = new List() { assignment, buildUpExpression }; - if (typeof(IInjectionAware).IsAssignableFrom(this.Type)) - blockItems.Add(Expression.Call(assignment, typeof(IInjectionAware).GetMethod("ParametersInjected"))); - blockItems.Add(instanceVar); // Final appearance of instanceVar, as this sets the return value of the block - completeExpression = Expression.Block(new[] { instanceVar }, blockItems); - } + // We always start with: + // var instance = new Class(.....) + // instance.Property1 = new .... + // instance.Property2 = new .... + var blockItems = new List() { assignment, buildUpExpression }; + // If it implements IInjectionAware, follow that up with: + // instance.ParametersInjected + if (typeof(IInjectionAware).IsAssignableFrom(this.Type)) + blockItems.Add(Expression.Call(instanceVar, typeof(IInjectionAware).GetMethod("ParametersInjected"))); + // Final appearance of instanceVar, as this sets the return value of the block + blockItems.Add(instanceVar); + var completeExpression = Expression.Block(new[] { instanceVar }, blockItems); this.creationExpression = completeExpression; return completeExpression; @@ -974,7 +971,9 @@ namespace Stylet var parameterExpression = Expression.Parameter(typeof(object), "inputParameter"); var typedParameterExpression = Expression.Convert(parameterExpression, this.type); + var expression = this.GetExpression(container, typedParameterExpression); this.implementor = Expression.Lambda>(this.GetExpression(container, typedParameterExpression), parameterExpression).Compile(); + return this.implementor; } } diff --git a/StyletUnitTests/StyletIoCParameterInjectionTests.cs b/StyletUnitTests/StyletIoCParameterInjectionTests.cs index 649236f..5460dac 100644 --- a/StyletUnitTests/StyletIoCParameterInjectionTests.cs +++ b/StyletUnitTests/StyletIoCParameterInjectionTests.cs @@ -53,7 +53,7 @@ namespace StyletUnitTests public C1 C1 = null; } - class Subject6 + class Subject6 : IInjectionAware { [Inject] public C1 C1 = null;