jab
jab copied to clipboard
Generic services with constraints causes a non-compilable code
Code for reproduction:
internal interface IService<T>{} where T : IAnotherService
class ServiceImplementation<T> : IService<T> where T : IAnotherService { }
internal interface IAnotherService{}
interface IService1 {}
class ServiceImplementation : IService1 { }
class ServiceImplementation2 : IAnotherService { }
[ServiceProvider]
[Singleton(typeof(IService<>), typeof(ServiceImplementation<>))]
[Singleton(typeof(IService1), typeof(ServiceImplementation))]
[Singleton(typeof(IAnotherService), typeof(ServiceImplementation2 ))]
partial class Container
{
}
Expected result:
The code is generated only for IService<IAnotherService>
.
Actual result:
The code is generated for IService<IAnotherService>
and for IService<IService1>
. Thus the generated code cannot be compiled since the type 'IService1' cannot be used as type parameter 'T': there is no implicit reference conversion from 'IService1' to 'IAnotherService'.
Hm, I can't repro this one. Are on the latest version?
This is the Program.cs
I used.
using Jab;
var c = new Container();
c.GetService<IService<IAnotherService>>();
internal interface IService<T> where T : IAnotherService {}
class ServiceImplementation<T> : IService<T> where T : IAnotherService { }
internal interface IAnotherService{}
interface IService1 {}
class ServiceImplementation : IService1 { }
class ServiceImplementation2 : IAnotherService { }
[ServiceProvider]
[Singleton(typeof(IService<>), typeof(ServiceImplementation<>))]
[Singleton(typeof(IService1), typeof(ServiceImplementation))]
[Singleton(typeof(IAnotherService), typeof(ServiceImplementation2 ))]
partial class Container
{
}