The ResetDefaults()
method switches the profile to String.Empty
. Which in your case it already was. This doesn't remove plugin types registered through Inject<T>(T object)
.
The Inject<T>(T object)
method registers the object as the default for the PluginType "T". In other words it overrides your current default which was the concrete type ValueProvider
.
The documentation of StructureMap is dated so my guess is that in earlier versions it worked the way it's described in the documentation but that is no longer the case.
So use the Inject<T>(T object)
method only if you want to override the default of a configured plugin type at run-time or use StructureMap profiles.
StructureMap does provide some ways to remove "eject" types from the container. One of them is:
ObjectFactory.Model.EjectAndRemoveTypes(match =>
match != null &&
match == typeof (TestValueProvider)
);
This code does remove the registration made by the Inject<T>(T object)
method but doesn't revert the default instance of type IValueProvider
. This means there is no longer a default instance for IValueProvider
.
Therefor ObjectFactory.GetInstance<IValueProvider>()
will throw an StructureMap Exception Code: 202
No Default Instance defined for PluginFamily ...
exception.
ObjectFactory.GetAllInstances<IValueProvider>().First()
will give you back the instance of ValueProvider
. The one you expect.
I am not really sure what your are trying to test here, but if they are unit-tests you should try to avoid the need for an IoC container (which also means depending on ObjectFactory
). If you do need an container use an abstraction of IContainer
which you can manage and create yourself. Some links to other SO questions backing this are: