Property Injection in ASP.NET Core is a dependency injection technique where dependencies are injected into a class’s properties instead of its constructor. The dependencies are instantiated and assigned to the properties during runtime by the dependency injection container. This approach is useful when a class has a large number of dependencies, and they are not required for constructing the object but are needed later at runtime.
To use property injection, the class’s properties must be marked with the [Inject] attribute or registered with the dependency injection container. The container will then inject the dependencies as required, and the properties can be used throughout the lifetime of the object.
It is important to note that Property Injection should be used sparingly, and Constructor Injection should be preferred whenever possible, as it is more explicit about the dependencies required by the class.
Asked: 2022-09-04 11:00:00 +0000
Seen: 1 times
Last updated: Mar 21 '22