Lamar provides the following syntax for building objects with a lambda:
serviceRegistry.For<ISomeType>().Use(x => { ... });
This would allow you to resolve ISomeType which would execute the registered delegate:
var someType = container.GetInstance<ISomeType>();
Is there a non-generic equivalent such as the following?
serviceRegistry.For(typeof(ISomeType)).Use(x => { ... });
I'm not seeing an overload for this.
After discovering that Lamar's
ServiceRegistryis derived fromServiceProvider, I realized that it would be possible to achieve this by using the ServiceProvider API:See .Net Fiddle Example