JasperFx / lamar

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

Unable to resolve Lazy<> or Func<> #177

Closed kieronlanning closed 5 years ago

kieronlanning commented 5 years ago

Hi,

I'm having a problem resolving anything that's in a constructor with Lazy<> or Func<>.

I've create a repo with a basic example consisting of three tests - one (working) with no lazy or func, and the other two with lazy and func registrations.

Is it something I'm doing/ not doing correctly?

https://github.com/kieronlanning/lamar-lazy-func-resolve

jeremydmiller commented 5 years ago

@kieronlanning At no point in that code are you using a Lamar container. I don't know offhand what the built in DI container supports for Lazy or Func, so you'll have to ask them.

This line:

IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider(true);

Builds the default AspNetCore ServiceProvider.

kieronlanning commented 5 years ago

@jeremydmiller Ah, I thought because I was using a ServiceRegistry rather than a ServiceCollection the call to BuildServiceProvider would build a Lamar container - my apologies! I see now it's an extension method.

I've updated to include (failing) .NET Core DI tests and working Lamar ones. Thanks for pointing me in the right direction!