Am trying out structuremap for the first time and am getting the following compiler error,
StructureMap Exception Code: 202
No Default Instance defined for PluginFamily Super.SuperCore.Core.DataAccess.IPersonRepository, Super.SuperCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
The place where am calling the interface:
private 开发者_如何学GoIPersonRepository _iPersonRepository;
public void Init() {
_iPersonRepository = ObjectFactory.GetInstance<IPersonRepository>();
}
My Interface Declaration:
[PluginFamily("Default")]
public interface IPersonRepository
{
List<string> getAllNames();
}
My StructureMap.config:
<?xml version="1.0" encoding="utf-8" ?>
<StructureMap>
<Assembly Name="Super.SuperWeb" />
<Assembly Name="Super.SuperCore" />
</StructureMap>
Can anyone point out where exactly am I going wrong.
First, that's not a compiler error, that's an exception, there is a very large difference, I won't go into that though.
In your configuration, you appear to be mixing and matching configuration methods. I typically pick one and stick to it. Here's the documentation
If you want to go the attribute route, you have to tell SM to scan for classes with attributes
If you want to go the xml route, make sure your structuremap.config is getting copied to the folder with the exe. I don't think you should have to, but you can explicitly load from the xml config like this
ObjectFactory.Initialize(x =>
{
x.AddConfigurationFromXmlFile("StructureMap.config");
});
If you want something that is strongly typed and compiler checked, try the registry dsl, it's the more modern configuration mechanism.
精彩评论