Created
August 28, 2015 01:58
-
-
Save gongdo/fba727275534beeb678b to your computer and use it in GitHub Desktop.
SimpleInjector 3.0.1 can't resolve OpenGeneric collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using SimpleInjector; | |
using System; | |
using System.Diagnostics; | |
using System.Linq; | |
namespace ConsoleApplication1 | |
{ | |
public class Foo { } | |
public class Bar { } | |
public class Zoo { } | |
public class Jar { } | |
public abstract class Selector<T1, T2> { } | |
public class FooBarSelector : Selector<Foo, Bar> { } | |
public class ZooJarSelector : Selector<Zoo, Jar> { } | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var container = new Container(); | |
var assemblies = new[] { typeof(Foo).Assembly }; | |
var types = container.GetTypesToRegister(typeof(Selector<,>), assemblies); | |
var registrations = types.Select(t => Lifestyle.Transient.CreateRegistration(t, container)); | |
container.RegisterCollection(typeof(Selector<,>), registrations); | |
container.Verify(); | |
// it will be okay: | |
var fooSelector = container.GetInstance<FooBarSelector>(); | |
var zooSelector = container.GetInstance<ZooJarSelector>(); | |
// but exception thrown bellow: | |
var fooGenericSelector = container.GetInstance<Selector<Foo, Bar>>(); | |
var zooGenericSelector = container.GetInstance<Selector<Zoo, Jar>>(); | |
Debug.Assert(fooSelector is FooBarSelector | |
&& zooSelector is ZooJarSelector); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment