For example, there's XController
and there's XService
, but there's also the YService
and I want to use it in several controllers without having to inject into the controller as a dependency in the following way:
private readonly IYService _yService;
XController(IYService yService)
{
_YService = YService;
}
Is there a cleaner way to do it? I want to use this service in several controllers since I'm logging the controllers and storing what has changed, the old value, the new value, and the date time. These are all stored into a database.
CodePudding user response:
Can use one of these
Setter/Property Injection
[Dependency] public IYService _yService { get; set; }
Method Injection
[InjectionMethod] public void Method(IYService _yService) { // your logic }
Please click here for more details
CodePudding user response:
i believe you can conjure up a service instance through the service collection. please search.