JasperFx / lamar

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

Invalid Expression Created using Implementation Factory #167

Closed Silvenga closed 5 years ago

Silvenga commented 5 years ago

Given the following code:

var container = new Container(x =>
{
    var serviceDescriptor = ServiceDescriptor.Transient(typeof(IWidget), provider => provider.GetRequiredService(typeof(AWidget)));
    x.Add(serviceDescriptor);
});

var result = container.GetInstance<MyClass>();

result.ShouldBeOfType<MyClass>();

The following is created:

System.ArgumentException: Expression of type 'System.Object' cannot be used for assignment to type 'StructureMap.Testing.Widget.IWidget'
   at System.Linq.Expressions.Expression.Assign(Expression left, Expression right)
   at Lamar.IoC.Instances.InlineLambdaCreationFrame`1.WriteExpressions(LambdaDefinition definition) in E:\Development\github.com\Silvenga\lamar\src\Lamar\IoC\Instances\InlineLambdaCreationFrame.cs:line 56
   at Lamar.IoC.Instances.FuncResolverDefinition.BuildResolver() in E:\Development\github.com\Silvenga\lamar\src\Lamar\IoC\Instances\FuncResolverDefinition.cs:line 50
   at Lamar.IoC.Instances.GeneratedInstance.BuildFuncResolver(Scope scope) in E:\Development\github.com\Silvenga\lamar\src\Lamar\IoC\Instances\GeneratedInstance.cs:line 104
   at Lamar.IoC.Instances.GeneratedInstance.buildResolver(Scope scope) in E:\Development\github.com\Silvenga\lamar\src\Lamar\IoC\Instances\GeneratedInstance.cs:line 217
   at Lamar.IoC.Instances.GeneratedInstance.ToResolver(Scope topScope) in E:\Development\github.com\Silvenga\lamar\src\Lamar\IoC\Instances\GeneratedInstance.cs:line 181
   at Lamar.IoC.Instances.ConstructorInstance.ToResolver(Scope topScope) in E:\Development\github.com\Silvenga\lamar\src\Lamar\IoC\Instances\ConstructorInstance.cs:line 88
   at Lamar.ServiceGraph.FindResolver(Type serviceType) in E:\Development\github.com\Silvenga\lamar\src\Lamar\ServiceGraph.cs:line 337
   at Lamar.IoC.Scope.GetInstance(Type serviceType) in E:\Development\github.com\Silvenga\lamar\src\Lamar\IoC\Scope.cs:line 140
   at Lamar.IoC.Scope.GetInstance[T]() in E:\Development\github.com\Silvenga\lamar\src\Lamar\IoC\Scope.cs:line 129
   at Lamar.Testing.Bugs.Test.METHOD_NAME() in E:\Development\github.com\Silvenga\lamar\src\Lamar.Testing\Bugs\Test.cs:line 18
jeremydmiller commented 5 years ago

Duplicate w/ #164