gordon-cs / gordon-360-api

The 360° Gordon Experience
11 stars 6 forks source link

Use primary constructors for Dependency Injection #1017

Closed EjPlatzer closed 7 months ago

EjPlatzer commented 7 months ago

.NET 8's new Primary Constructor syntax adds a much cleaner way to declare a class that takes some inputs for construction and stores those inputs throughout the lifetime of the object.

This is ideal for Dependency Injection, because we can replace private readonly fields initialized in the constructor with inputs defined in the primary constructor. This syntax is simpler, easier to read and write, and familiar because it mimics function signatures. It is also the recommended way to write classes with these kinds of dependencies, such that Microsoft even created a linting rule for it that is automatically enabled from .NET 8 onwards.

EjPlatzer commented 7 months ago

LGTM, but as this is exclusively a syntactic update I would warn against making changes which will confuse the current SP team in their work. Up to your discretion as you have worked with them more.

Thanks for raising that concern. It's a good point, but I think we should be fine, since these changes are unlikely to overlap their work.