tags:

views:

482

answers:

1

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
   {
      ...
   }
}

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!

+2  A: 

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.

KevM
I've added following code to public SysMsgManager()var container = new Container(config => { config.For<ISysMsgRepository>().Use<SysMsgRepository>(); }); _SysMsgRepository = ObjectFactory.GetInstance<ISysMsgRepository>();still got the same error.
sean717
Can you send me paste of your test code?
KevM
Thanks for your help. I end up getting everything working in CastleWindsor. I think at one point I get it working with the code your posted. But I still want to have the configuration via XML.
sean717
What exactly do you need to do via XML? Just curious what we are missing in StructureMap.
KevM