Skip to content

Instantly share code, notes, and snippets.

@chandu
Created November 2, 2013 19:51
Show Gist options
  • Select an option

  • Save chandu/7282799 to your computer and use it in GitHub Desktop.

Select an option

Save chandu/7282799 to your computer and use it in GitHub Desktop.
StructureMap Interface and Class Resolution issue.
[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