JasperFx / lamar

Fast Inversion of Control Tool and Successor to StructureMap
https://jasperfx.github.io/lamar
MIT License
566 stars 117 forks source link

failing test proving ContainerValidationException for IServiceScopeFactory #228

Closed lpodolak closed 4 years ago

lpodolak commented 4 years ago

This is only a failing test proving the scenario that I encountered while upgrading my asp.net core api to .net core 3.1 and switching from StructureMap to Lamar.

When we run AssertConfigurationIsValid and there is a service that depends on IServiceScopeFactory, the AssertConfigurationIsValid throws ContainerValidationException while it should not.

The services.AddHealthChecks() configures DefaultHealthCheckService which depends on IServiceScopeFactory. These are all internal classes that we can't change to not use IServiceScopeFactory. I didn't notice problems with using healthchecks in the api context - i.e. they work fine, DefaultHealthCheckService is resolved correctly and IServiceScopeFactory invokes CreateScope() correctly. That's why I think that this is a problem specific only to when running AssertConfigurationIsValid()

FYI, I couldn't make neither VS, nor Rider to compile the solution correctly. I installed I think all combinations of sdks (also 3.0.100), but I always kept ending with " Microsoft.NET.TargetFrameworkInference.targets(150, 5): [NETSDK1045] The current .NET SDK does not support targeting .NET Standard 2.1. Either target .NET Standard 2.0 or lower, or use a version of the .NET SDK that supports .NET Standard 2.1." Hopefully, I was able to compile everything and run tests from rake, so I hope everything will compile for you in the IDE as well

lpodolak commented 4 years ago

The details of exception: Lamar.IoC.ContainerValidationException: Error in new DefaultHealthCheckService(scopeFactory, options, logger) System.InvalidOperationException: Frame type Lamar.IoC.Resolvers.CastRootScopeFrame does not implement IResolverFrame".

Mentioned on gitter: