Closed hellfirehd closed 5 years ago
This one is funny, I just spent two hours debugging this and realized the solutions is really simple. Comment out your .ConfigureContainer()
in the failing test and run it again. 😄
You're creating a new container against an existing ServiceRegistry
, the new container runs the scan a second time, adding all the registrations to the existing ServiceRegistry
again.
D'oh! Thank you so much!
Basically, I'm trying to use Lamar for it's type scanning and registries while still relying on Microsoft's DI framework. In particular, I want
ConnectImplementationsToTypesClosing(typeof(IHandleMessages<>))
.However, once the host is built and the
ServiceProvider
is returned,ServiceProvider.GetServices<IHandleMessages<FooMessage>>()
gives me back two instances when there should only be one, and four when there should be two.This gist demonstrates it perfectly.
Can anyone tell me what I'm doing wrong? (I mean, besides using Microsoft.Extensions.DependencyInjection instead of just pure Lamar. 😛)