-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
src/StructureMap.Testing/Bugs/GenericVarianceResolution.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,62 @@ | ||
namespace StructureMap.Testing.Bugs | ||
{ | ||
using System.Linq; | ||
using NUnit.Framework; | ||
using StructureMap.Graph; | ||
|
||
public interface INotificationHandler<in TNotification> | ||
{ | ||
void Handle(TNotification notification); | ||
} | ||
|
||
public class BaseNotificationHandler : INotificationHandler<object> | ||
{ | ||
public void Handle(object notification) | ||
{ | ||
|
||
} | ||
} | ||
|
||
public class OpenNotificationHandler<TNotification> : INotificationHandler<TNotification> | ||
{ | ||
public void Handle(TNotification notification) | ||
{ | ||
|
||
} | ||
} | ||
|
||
public class Notification { } | ||
|
||
public class ConcreteNotificationHandler : INotificationHandler<Notification> | ||
{ | ||
public void Handle(Notification notification) | ||
{ | ||
|
||
} | ||
} | ||
|
||
[TestFixture] | ||
public class GenericVarianceResolution | ||
{ | ||
[Test] | ||
public void RegisterMultipleHandlersOfSameInterface() | ||
{ | ||
var container = new Container(x => | ||
{ | ||
x.Scan(s => | ||
{ | ||
s.TheCallingAssembly(); | ||
s.AddAllTypesOf(typeof (INotificationHandler<>)); | ||
}); | ||
}); | ||
|
||
var handlers = container.GetAllInstances<INotificationHandler<Notification>>(); | ||
|
||
handlers.Single(h => h.GetType() == typeof (ConcreteNotificationHandler)); | ||
//handlers.Single(h => h.GetType() == typeof(OpenNotificationHandler<Notification>)); | ||
handlers.Single(h => h.GetType() == typeof(BaseNotificationHandler)); | ||
|
||
handlers.Count().ShouldEqual(3); | ||
} | ||
} | ||
} |
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