Created
November 2, 2013 19:51
-
-
Save chandu/7282799 to your computer and use it in GitHub Desktop.
StructureMap Interface and Class Resolution issue.
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
| [TestFixture] | |
| public class IoCTests | |
| { | |
| [Test] | |
| public void Can_Resolve_same_instance_when_asked_by_interface_and_class() | |
| { | |
| //Arrange | |
| ObjectFactory.Initialize(x => | |
| { | |
| x.For<FooBar>() | |
| .HybridHttpOrThreadLocalScoped() | |
| .Use<FooBar>(); | |
| x.For<IFooBar>() | |
| .HybridHttpOrThreadLocalScoped() | |
| .Use<FooBar>(); | |
| }); | |
| //Act | |
| var fooBar = ObjectFactory.GetInstance<FooBar>(); | |
| var iFooBar = ObjectFactory.GetInstance<IFooBar>(); | |
| //Assert | |
| Assert.AreEqual(fooBar.GetHashCode(), iFooBar.GetHashCode()); | |
| } | |
| } | |
| public interface IFooBar | |
| { | |
| void DoFoo(); | |
| } | |
| public class FooBar : IFooBar | |
| { | |
| public void DoFoo() | |
| { | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment