开发者

StructureMap exception: No Default Instance defined for PluginFamily

开发者 https://www.devze.com 2022-12-20 17:38 出处:网络
I have a SysMsgManager class defined in CoreService project as following: public class SysMsgManager {

I have a SysMsgManager class defined in CoreService project as following:

public class SysMsgManager 
{
    private ISysMsgRepository _SysMsgRepository;

    public SysMsgManager()
    {
        _SysMsgRepository = ObjectFactory.GetInstance<ISysMsgRepository>();
    }

    ....
}

In my DataAccess project I have 'ISysMsgRepository' interface and two concrete implementations defined as following:

namespace DataAccess.Repository
{
   [Pluggable("Default")]
   public class SysMsgRepository : ISysMsgRepository
   {
      ...
 开发者_JS百科  }
}

namespace DataAccess.Repository
{
    [Pluggable("Stub")]
    public class SysMsgRepository_Test : ISysMsgRepository
    {
        ...
    }
}

and this is what I have in my StructureMap.config file

<StructureMap>

<Assembly Name="CoreService" /> 
<Assembly Name="DataAccess" />

<PluginFamily
    Assembly="DataAccess"
    Type="DataAccess.Repository.ISysMsgRepository"
    DefaultKey="Default" />

</StructureMap>

When I try to run my app, I got the following error:

StructureMap Exception Code: 202\nNo Default Instance defined for PluginFamily DataAccess.Repository.ISysMsgRepository, DataAccess, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Can anyone help me to solve this problem? Thanks!


Unfortunately I have little familiarity with configuring StructureMap via Xml. Let me show you how it is done using C#.

var container = new Container(config=>
{
  config.For<ISysMsgRepository>().Use<SysMsgRepository>();
});

It seems you are using the standard naming convention for your interfaces and classes (just tacking an I onto the front of the class name). If you do that for all your types you can just configure your container like this:

var container = new Container(config=>
{
    config.Scan(scan =>
    {
        scan.TheCallingAssembly();
        scan.WithDefaultConventions();
    });
});

I hope this helps. It is much easier to configure your container using code rather than Xml. Give it a try. You'll be a convert.

0

精彩评论

暂无评论...
验证码 换一张
取 消