J'ai 2 services que vous pouvez voir avec ces constructeurs:utilisation ninject à la fois le service crée une dépendance cyclique C#
public ReceptionService(DataContext ctx, IPaymentService PaymentService, IReceptionHistoryService ReceptionHistoryService, ITestService TestService, ITestRepository TestRepository ,IReferredRepository ReferredRepository, IAutomotiveRepository AutomotiveRepository,IReceptionRepository ReceptionRepository,IReferredService ReferredService,IAutomotiveService AutomotiveService)
{
_ctx = ctx;
_automotiveRepository = AutomotiveRepository;
_referredRepository = ReferredRepository;
_receptionRepository = ReceptionRepository;
_referredService = ReferredService;
_automotiveService = AutomotiveService;
_testService = TestService;
_receptionHistoryService = ReceptionHistoryService;
_paymentService = PaymentService;
}
Un autre:
public TestService(DataContext ctx, IReceptionService ReceptionService ,IParameterService ParameterService, ILineService LineService, ITestRepository TestRepository, IReceptionHistoryService ReceptionHistoryService
, IReceptionHistoryRepository ReceptionHistoryRepository)
{
_TestRepository = TestRepository;
_parameterService = ParameterService;
_receptionHistoryRepository = ReceptionHistoryRepository;
_receptionHistoryService = ReceptionHistoryService;
_lineService = LineService;
_ctx = ctx;
}
Avec ces tout constructeurs fonctionne très bien mais quand je l'ajoute ReceptionService
au TestService
comme ceci:
public TestService(DataContext ctx, IReceptionService ReceptionService ,IParameterService ParameterService, ILineService LineService, ITestRepository TestRepository, IReceptionHistoryService ReceptionHistoryService
, IReceptionHistoryRepository ReceptionHistoryRepository)
{
_TestRepository = TestRepository;
_parameterService = ParameterService;
_receptionHistoryRepository = ReceptionHistoryRepository;
_receptionHistoryService = ReceptionHistoryService;
_lineService = LineService;
_ReceptionService = ReceptionService;
_ctx = ctx;
}
Je reçois cette erreur:
Error activating IReceptionService using binding from IReceptionService to ReceptionService
A cyclical dependency was detected between the constructors of two services.
Activation path:
5) Injection of dependency IReceptionService into parameter ReceptionService of constructor of type TestService
4) Injection of dependency ITestService into parameter TestService of constructor of type ReceptionService
3) Injection of dependency IReceptionService into parameter ReceptionService of constructor of type TestService
2) Injection of dependency TestService into parameter instance of constructor of type NinjectIISHostingServiceHost{TestService}
1) Request for NinjectIISHostingServiceHost{TestService}
Suggestions:
1) Ensure that you have not declared a dependency for IReceptionService on any implementations of the service.
2) Consider combining the services into a single one to remove the cycle.
3) Use property injection instead of constructor injection, and implement IInitializable
if you need initialization logic to be run after property values have been injected.
Vous injectez ITestService dans ReceptionService et IReceptionService dans TestService. Je ne suis pas surpris que ça ne marche pas. Je ne suis pas sûr de savoir quelle est votre question, mais si cela va dans le sens de "comment se débarrasser de cette erreur?", La réponse est "ne faites pas dépendre A d'une dépendance de B si B dépend de UNE". – oerkelens
Copie possible de [Cyclic dependency with ninject] (https://stackoverflow.com/questions/3511547/cyclic-dependency-with-ninject) – mjwills
@oerkelens J'ai besoin du service de réception à l'intérieur du service de test –