Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
making ConnectImplementationsToTypesClosing smart enough to deal with…
… co/contra variance better. Closes GH-320
- Loading branch information
1 parent
b6b3f15
commit 3b167d8
Showing
5 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/StructureMap.Testing/Bugs/Bug_320_generic_parent_child_relationship.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using StructureMap.Graph; | ||
|
||
namespace StructureMap.Testing.Bugs | ||
{ | ||
[TestFixture] | ||
public class Bug_320_generic_parent_child_relationship | ||
{ | ||
public class Parent { }; | ||
public class Child : Parent { } | ||
public class ConcreteChild : Child { } | ||
|
||
public interface IGeneric<in T> where T : class { } | ||
public class GenericClass1 : IGeneric<Parent> { } | ||
public class GenericClass2 : IGeneric<Child> { } | ||
//public class GenericClass3 : IGeneric<ConcreteChild> { } | ||
|
||
[Test] | ||
public void StructureMap_Resolves_Generic_Child_Classes() | ||
{ | ||
typeof(IGeneric<ConcreteChild>).IsAssignableFrom(typeof(GenericClass1)).ShouldBeTrue(); | ||
typeof(IGeneric<ConcreteChild>).IsAssignableFrom(typeof(GenericClass2)).ShouldBeTrue(); | ||
//Assert.IsTrue(typeof(IGeneric<ConcreteChild>).IsAssignableFrom(typeof(GenericClass3))); | ||
|
||
var container = new Container(cfg => | ||
{ | ||
cfg.Scan(scan => | ||
{ | ||
scan.TheCallingAssembly(); | ||
scan.ConnectImplementationsToTypesClosing(typeof(IGeneric<>)); | ||
}); | ||
}); | ||
|
||
var what = container.WhatDoIHave(); | ||
Debug.WriteLine(what); | ||
|
||
var instances = container.GetAllInstances<IGeneric<ConcreteChild>>(); | ||
|
||
instances.Any(t => t.GetType() == typeof (GenericClass1)).ShouldBeTrue(); | ||
instances.Any(t => t.GetType() == typeof(GenericClass2)).ShouldBeTrue(); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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