Yes, we can use readonly fields with .NET dependency injection.
Here's an example of such behavior with dependency injection in .NET:
C#
class OrderService {
private readonly CartService _cartService;
public OrderService(CartService cartService) {
_cartService = cartService;
}
}
The OrderService above has a dependency of CartService which is unknown until the runtime. We use private readonly field for the CartService because it's passed via OrderService constructor.