Reputation: 7374
I'm using StructureMap 2.6.1
This is the code from Bootstrapper.cs:
ObjectFactory.Initialize(x => x.For<IFoo>().Use<Foo>());
When I run application, I get the following exception:
No Default Instance defined for PluginFamily IFoo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
I don't get an exception when I use this obsolete code:
ForRequestedType<IFoo>()
.TheDefault.Is.OfConcreteType<Foo>();
Can anyone tell me the latest syntax for ObjectFactory's initializer?
Thank you.
Upvotes: 2
Views: 1145
Reputation: 68456
Each time you call Initialize, you're resetting the ObjectFactory. I.e. in the following scenario:
ObjectFactory.Initialize(x => x.For<IFoo>().Use<Foo>());
ObjectFactory.Initialize(x => x.For<IBaz>().Use<Baz>());
You've only actually mapped out IBaz
to Baz
.
You should use an ApplicationRegistry instead:
public class ApplicationRegistry : Registry
{
public ApplicationRegistry()
{
For<IFoo>().Use<Foo>();
For<IBaz>().Use<Baz>();
}
}
And use that in your Initialize method:
ObjectFactory.Initialize(x => x.AddRegistry(new ApplicationRegistry()));
Upvotes: 3