'IServiceCollection StackOverflow exception
I tried moving all my DI instructions to a separate class using an extension method, on runtime I get a stack-overflow exception with no further details
public static IServiceCollection AddMyServices(this IServiceCollection services)
{
var dns_client = new LookupClient();
services.AddSingleton<ImySQLService, mySQLService>();
services.AddSingleton<ILoggerService, LoggerService>();
services.AddSingleton<IOrginizationRepository, OrginizationRepository>();
services.AddSingleton<IEdiModelRepository, EdiModelRepository>();
services.AddSingleton<IEdiUserProfileRepository, EdiUserProfileRepository>();
services.AddSingleton<IEdiSegmentRepository, EdiSegmentRepository>();
services.AddSingleton<IConnectionRepository, ConnectionRepository>();
services.AddSingleton<IVariableRepository, VariableRepository>();
services.AddSingleton<ISegmentPictureRepository, SegmentPictureRepository>();
services.AddSingleton<IAuthorizationHandler, HasScopeHandler>();
services.AddSingleton<IEdiExampleRepository, EdiExampleRepository>();
services.AddSingleton<IDocumentReceiverRepository, DocumentReceiverRepository>();
services.AddSingleton<IDocumentToEdiRepository, DocumentToEdiRepository>();
services.AddSingleton<IEdiValidatorRepository, EdiValidatorRepository>();
services.AddSingleton<IDnsLookupRepository, DnsLookupRepository>();
services.AddSingleton<ILookupClient>(dns_client);
services.AddHttpClient<IPylonAPIService, PylonAPIService>();
...
return services;
}
- What could possibly be causing this?
- How would I got about debugging such an exception that has no further messages
- I tried to wrap it with try - catch but to no avail
Thanks in advance!
Solution 1:[1]
I found the problem, I had
builder.Services.AddMyServices();
twice , once in my Program.cs and once in the Extension Method itself
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SecurityObscurity |
