Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinRL/2492561 to your computer and use it in GitHub Desktop.
Save MartinRL/2492561 to your computer and use it in GitHub Desktop.
StructureMapObjectFactoryResetDefaultsBug
using System;
using FluentAssertions;
using StructureMap;
using Xunit;
namespace StructureMapObjectFactoryResetDefaultsBug
{
public class Reproducer
{
[Fact]
public void Given_ObjectFactory_Inject_When_ObjectFactory_ResetDefaults_Then_configured_instance_is_returned()
{
ObjectFactory.Initialize(i => i.For<IFoo>().Use<FooProd>());
ObjectFactory.Inject<IFoo>(new FooStub());
ObjectFactory.GetInstance<IFoo>().Should().BeOfType<FooStub>();
ObjectFactory.ResetDefaults();
ObjectFactory.GetInstance<IFoo>().Should().BeOfType<FooProd>(); // fails
}
}
public interface IFoo {}
public class FooProd : IFoo {}
public class FooStub : IFoo {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment