Ask Your Question
3

What is Property Injection in ASP.NET Core?

asked 2022-09-04 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2022-03-21 23:00:00 +0000

qstack gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-09-04 11:00:00 +0000

Seen: 1 times

Last updated: Mar 21 '22