Why primary constructor works in my project based on .NET 4.8
From my understanding, primary constructor was introduced in C#12 with .NET 8. And I use it for dependency injection with AutoFac. And langVersion is set as Latest Major. Code looks like this: public interface IService { Distance GetDistance(); } public class ExampleController(IService service) : ControllerBase { [HttpGet] public ActionResult Get() { return service.GetDistance(); } }
From my understanding, primary constructor was introduced in C#12 with .NET 8.
And I use it for dependency injection with AutoFac. And langVersion is set as Latest Major.
Code looks like this:
public interface IService
{
Distance GetDistance();
}
public class ExampleController(IService service) : ControllerBase
{
[HttpGet]
public ActionResult Get()
{
return service.GetDistance();
}
}