I have to create services for my project, that implement other services, therefore I created many Interfaces and for some services I inject the interface to use the methods, but when I tried to compile my project I become an error, this is driving me nuts, can someone please tell me what am I doing wrong?
the interface:
public interface IGoogleExtensions
{
dynamic GetEntetiesTypeorWorth(WebhookRequest request, string entetie, bool wertHohlen);
bool HasDisplay(WebhookRequest request);
string StringBuilder(int position, string text, string texttoinsert);
}
The Service
public class GoogleExtensionsService : IGoogleExtensions
{
private readonly IGoogleVitalwertResponseHelper _googleVitalwertResponseHelper;
public GoogleExtensionsService(IGoogleVitalwertResponseHelper googleVitalwertResponseHelper)
{
_googleVitalwertResponseHelper = googleVitalwertResponseHelper;
}
public dynamic GetEntetiesTypeorWorth(WebhookRequest request, string entetie, bool wertHohlen)
{
var entetieType = request.QueryResult.Parameters.Fields;
var type = TextResponses.FehlerMeldung2;
[...]
type = TextResponses.Alle;
}
return type;
}
public bool HasDisplay(WebhookRequest request)
{
string capability = request.OriginalDetectIntentRequest.Payload.Fields[ProtobufFields.Surface].StructValue.Fields[ProtobufFields.Capabilities].ToString();
if (capability.Contains(ProtobufFields.Screen_output))
return true;
return false;
}
public string StringBuilder(int position, string text, string texttoinsert)
{
StringBuilder sb = new StringBuilder(text);
sb.Insert(position, texttoinsert);
return sb.ToString();
}
References in Start.up
services.AddTransient<IGoogleResponseService, GoogleResponseService>();
services.AddTransient<IGoogleService, GoogleRequestService>();
services.AddTransient<IGoogleExtensions, GoogleExtensionsService>();
services.AddTransient<IGoogleVitalwertResponseHelper, GoogleVitalwertResponseService>();
services.AddTransient<IGoogleVitalwertRequest, GoogleVitalwertRequest>();
services.AddTransient<IGoogleMenuePlanRequest, GoogleMenuePlanRequestService>();
services.AddTransient<IGoogleMenuePlanResponseHelper, GoogleMenuePlanResponseService>();
services.AddTransient<IGoogleMedikamentRequest, GoogleMedikamentRequestService>();
services.AddTransient<IGoogleMedikamentResponse, GoogleMedikamentResponseService>();
services.AddTransient<IGoogleBerichtResponse, GoogleBerichResponseService>();
I′m dealing with the following error:
Host terminated unexpectedly
System.AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: XXX.Microservices.Xxx.Api.Contract.Services.IGoogleService Lifetime: Transient ImplementationType: XXX.Microservices.Xxx.Api.Services.GoogleRequestService': A circular dependency was detected for the service of type 'XXX.Microservices.Xxx.Api.Contract.Services.IGoogleExtensions'.
XXX.Microservices.Xxx.Api.Contract.Services.IGoogleService(XXX.Microservices.Xxx.Api.Services.GoogleRequestService) -> XXX.Microservices.Xxx.Api.Contract.Services.IGoogleExtensions(XXX.Microservices.Xxx.Api.Services.GoogleExtensionsService) -> XXX.Microservices.Xxx.Api.Contract.Services.IGoogleVitalwertResponseHelper(XXX.Microservices.Xxx.Api.Services.GoogleVitalwertResponseService) -> XXX.Microservices.Xxx.Api.Contract.Services.IGoogleExtensions) (Error while validating the service descriptor 'ServiceType: XXX.Microservices.Xxx.Api.Contract.Services.IGoogleExtensions Lifetime: Transient ImplementationType: XXX.Microservices.Xxx.Api.Services.GoogleExtensionsService': A circular dependency was detected for the service of type 'XXX.Microservices.Xxx.Api.Contract.Services.IGoogleExtensions'.
XXX.Microservices.Xxx.Api.Contract.Services.IGoogleExtensions(XXX.Microservices.Xxx.Api.Services.GoogleExtensionsService) -> XXX.Microservices.Xxx.Api.Contract.Services.IGoogleVitalwertResponseHelper(XXX.Microservices.Xxx.Api.Services.GoogleVitalwertResponseService) -> XXX.Microservices.Xxx.Api.Contract.Services.IGoogleExtensions)
Edit
public class GoogleVitalwertResponseService : IGoogleVitalwertResponseHelper
{
private readonly IGoogleResponseService _googleResponseService;
private readonly IGoogleExtensions _googleExtensions;
private readonly IGoogleVitalwertResponseHelper _googleVitalwertResponseHelper;
public GoogleVitalwertResponseService(IGoogleResponseService googleResponseService, IGoogleExtensions googleExtensions, IGoogleVitalwertResponseHelper googleVitalwertResponseHelper)
{
_googleResponseService = googleResponseService;
_googleExtensions = googleExtensions;
_googleVitalwertResponseHelper = googleVitalwertResponseHelper;
}
public WebhookResponse VitalwertListResponse(WebhookRequest request, List<VitalwertOutput> vitalList, string vitalwertReference)
{
var session = new List<int>();
var items = new List<Value>();
int counter = 0;
...
}
public WebhookResponse VitalwertUebersicht(WebhookRequest request, ICollection<VitalwertOutput> vitalList, ICollection<VitalwertKategorie> Definitionen)
{
var items = new List<Value>();
....
return _googleResponseService.BuildListResponse(request, items, "Ich habe " + items.Count + " Vitalwerte gefunden", 3, SessionNames.SessionVitalwertUebersicht, session, null, null, null);
}
public string GetAktuellTag(string tag, DayOfWeek dayname)
{
DateTime today = DateTime.Parse(tag);
...
}
public List<KeyValuePair<string, int>> GenerateImageLinks()
{
var list = new List<KeyValuePair<string, int>>();
list.Add(new KeyValuePair<string, int>(ImagesURLS.Stethoscope, 1));
return list;
}
public string GenerateLink(List<KeyValuePair<string, int>> list, int DefinitionId)
...
var sub = vitalart.Substring(1, vitalart.Length - 2);
return sub;
}
question from:
https://stackoverflow.com/questions/65869936/problem-with-circular-dependency-in-asp-net-core