primary constructor

Constructor parameters written straight after a class name, as in class ProductService(IProductRepository repository), which stay in scope for the whole class body.

In more detail

Added for classes in C# 12, it removes the private readonly field and the assignment that constructor injection used to need. Records have had primary constructors from the start.

Related terms

Taught in

References