-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: base and child class with the same parameter name #123
Comments
Hello, what version of this package are you using ? There is no version 2.5.1 or 2.5.0. Did you mean 5.2.1 and 5.2.0 ? I've done some fixes yersterday about this specific case, so maybe you are talking about version 5.4.1 ? Can you give a sample of what was working before and what is not working now ? |
Sorry, I don't know why I typed 2.5.1. classes: [AutoConstructor]
public abstract partial class BaseClas
{
private readonly ILogger _logger;
}
[AutoConstructor]
public sealed partial class ChildClass : BaseClas
{
private readonly ILogger<ChildClass> _logger;
} with 5.4.0, it works well as I expected. partial class ChildClass
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("AutoConstructor", "5.0.0.0")]
public ChildClass(Microsoft.Extensions.Logging.ILogger<Ex3.CryptoProviders.Solana.Tests.ChildClass> logger) : base(logger)
{
this._logger = logger;
}
} with 5.4.1, it require a new partial class ChildClass
{
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("AutoConstructor", "5.0.0.0")]
public ChildClass(Microsoft.Extensions.Logging.ILogger<Ex3.CryptoProviders.Solana.Tests.ChildClass> logger, Microsoft.Extensions.Logging.ILogger b0__logger) : base(b0__logger)
{
this._logger = logger;
}
} |
It is what I was thinking you experienced. And it is not actually a bug, it is was it always should have been and it is what is expected since 5.4.1. I didn't think it would cause many problems because for the most parts, the code that have been fixed did not compile. It only worked in your case because The fact that it worked was only because it was the same parameter name and by chance, the child type injected was inheriting the other, there is no type inheritance checking in this library. Can you change the |
@k94ll13nn3 |
However, it is indeed difficult to judge because it seems impossible to determine the inheritance relationship between ILoggers at the stage of SG. |
I will see what I can do to allow you to override the current behavior in order to have only one logger. |
Version You can replace you child code with this and it should be back as it was. [AutoConstructor(matchBaseParameterOnName: true)]
public sealed partial class ChildClass : BaseClas
{
private readonly ILogger<ChildClass> _logger;
} Let me know what you think of this solution before I release a new version. |
Thanks, you are really helpful! |
since version 2.5.1
if base class is injected
ILogger logger
and child class is injectedILogger<T> logger
.it will create two parameter for child class, but as we all know, it will fail to inject ILogger from MSDI.
in version 2.5.0, it will be ok to handle the issue a show above, because I can ajust the parameter order by myself to make it works.
The text was updated successfully, but these errors were encountered: