Scrutor
Scrutor copied to clipboard
Support co- and contra-variance
Basically support this:
https://github.com/aspnet/DependencyInjection/issues/453
But do it during registration/scanning-time. StructureMap does this when it scans, and I had to add this manually to MediatR's MS DI extensions. See this code I borrowed from StructureMap:
https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection/blob/master/src/MediatR.Extensions.Microsoft.DependencyInjection/ServiceCollectionExtensions.cs#L55
This code is pretty complicated inside of StructureMap, so I'd suggest pinging @jeremydmiller for tips on what does what there.
You have to do the evaluation lazily when you request a closed type for the first time. What StructureMap does is to cache a list of all the "candidate" concrete types -- whether closed or open -- that implement the open interface (IService<T>
). At the first request for a specific IService<ISomething>
, SM will figure out which concrete types could be cast to the IService<ISomething>
.
Massive PITA all the way around.