.NET Core transition: Inject service interfaces wherever possible
See original GitHub issueThis task is up for grabs, for contributing to the .NET Core transition project
On the development branch of the .net core transition project netcore/dev
, we have used Current.Services.*
a lot.
When this is used, we cannot move the class into Umbraco.Abstractions or Umbraco.Infrastructure.
This task is about eliminating the usage of Current.Services.*
in general, by replacing it with a constructor injection of the interface of the given service that is in use. E.g. Current.Services.LocalizationService
has to be replaced with injection of ILocalizationService
.
Expected Procedure:
- Find an instance class that uses
Current.Services.*
. - Add the interface of the service to the constructor.
- Save the variable in a private readonly field.
- Replace the usages of
Current.Services.*
with the field. - Make sure the project builds
- Often you will need to inject this into classes that uses this specific class
- Ensure unit tests all pass
- Repeat the process
If any questions, feel free to ask 😃
Feel free to resolve this task in multiple smaller PRs, Due to the fact long running feature branch most likely have merge conflict with netcore/dev
Issue Analytics
- State:
- Created 4 years ago
- Comments:20 (12 by maintainers)
In then end, I only fixed 6 of the 110 references to Current.Services. The rest break out as follows:
50 - Unit tests (these could likely be done, but not tonight) 40 - Attribute classes (best done with .NET Core and the TypeFilterAttribute) 9 - Default constructors calling DI constructors (see question above) 4 - Extension classes (would need to refactor or add arguments) 1 - PublishedContent with the explicit comment “we don’t want each published content to hold a reference to the service”
Let me check …