You can use the activation context to find the parameter used in the parent's constructor. Like this:
kernel.Bind<IConnector>()
.To<AuditingConnector>()
.WhenInjectedInto<LoggingConnector>()
.WithConstructorArgument("id",
ctx => ctx.Request.ParentContext.Parameters
.Single(x => x.Name == "id")
.GetValue(ctx, null));
Or alternatively, you can set a custom instance provider to use with your factory which passes the parameters down the chain:
kernel.Bind<IConnectorFactory>().ToFactory(() => new CustomInstanceProvider());
where CustomInstanceProvider
is as follows:
public class CustomInstanceProvider : StandardInstanceProvider
{
protected override ConstructorArgument[] GetConstructorArguments(MethodInfo methodInfo, object[] arguments)
{
var parameters = methodInfo.GetParameters();
var constructorArguments = new ConstructorArgument[parameters.Length];
for (int i = 0; i < parameters.Length; i++)
{
constructorArguments[i] = new ConstructorArgument(parameters[i].Name, arguments[i], true);
}
return constructorArguments;
}
}