Autowiring properties in base classes not working in .net Core 2
See original GitHub issueI have a .Net Core 2 app and an API controller class which inherits from an abstract base class:
[Route("api/[controller]")]
public class MyController : BaseController
On the base controller I have:
public ICommandProcessor CommandProcessor { get; set; }
In my StartUp.cs I have:
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
.Where(t => t.IsSubclassOf(typeof(BaseController)))
.PropertiesAutowired();
However, the CommandProcessor property is always null. I have tried moving it to the derived class and tried registering the type directly as follows:
builder.RegisterType<MyController>().PropertiesAutowired();
and the also the base class:
builder.RegisterType<BaseController>().PropertiesAutowired();
I have tried what is suggested here and here amongst other posts but nothing seems to work, which makes me think that it is an issue in .Net Core 2.
When I inject the ICommandProcessor into the controller constructer it is wired up fine.
Any ideas?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Autowiring properties in base classes not working in ASP. ...
I have a .Net Core 2 app and an API controller class which inherits from an abstract base class: [Route("api/[controller]")] public class ......
Read more >Dependency injection into controllers in ASP.NET Core
Discover how ASP.NET Core MVC controllers request their dependencies explicitly via their constructors with dependency injection in ASP.
Read more >5. The IoC container
It is a process whereby objects define their dependencies, that is, the other objects they work with, only through constructor arguments, arguments to...
Read more >Top 10 Most Common Spring Framework Mistakes
Common Mistake #5: Improperly Dealing with Multithreading. Regardless of whether it is encountered in desktop or web apps, Spring or no Spring, multithreading ......
Read more >Spring - IoC Container (With Examples)
It does not allow defining autowire with simple properties such as primitives, Strings, and Classes. This limitation is by design. When using ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Did you add controllers as services?
in aspnetcore 2.2.it is not work