tags:

views:

163

answers:

1

Ok, I wrote this question up earlier today but I decided to delete it because I thought the question wasn't worded very well. I decided to wait until I had more time to compose it at home :). I am just getting started with IOC/DI. I have done some research on which framework to use and decided to give StructureMap a spin. The following is the first tutorial I used: http://dimecasts.net/Casts/CastDetails/39 by Derik Whittaker.

Anyways, I got everything working like a dream with EVERYTHING is hosted in the same project. Here is my sample code:

[PluginFamily("SMTest",IsSingleton=true)]
public interface IVehicle
{
     byte TopSpeed {set;get;}
     byte MPG { set; get; }

}

[Pluggable("SMTest")]
public class Car : IVehicle
{
    private byte mTopSpeed;
    private byte mMPG;
    #region IVehicle Members

    byte IVehicle.TopSpeed
    {
        get
        {
            return mTopSpeed;
        }
        set
        {
            mTopSpeed = value;
        }
    }

   public interface IConsumer
  {

    IVehicle Car { get; set; }
  }

     [Pluggable("SMTest")]
public class Consumer : StructureMapBasic.IConsumer
{
    private IVehicle mCar;

    public Consumer(IVehicle lcar)
    {
        Car = lcar;    
    }

    public IVehicle Car { set; get; }


    byte IVehicle.MPG
    {
        get
        {
            return mMPG;
        }
        set
        {
            mMPG = value;
        }
    }

    #endregion
}

So anyways if i create the project above into a command line program and do the following:

var consumer = ObjectFactory.GetInstance<IConsumer>();

It works perfectly. No problems at all. When i create a seperate project in the solution and then change the project above to a DLL. I get the following error:

Test method StructureMapBasic.ConsumerTest.ConsumerConstructorTest 
threw exception:  StructureMap.StructureMapException: StructureMap 
Exception Code:  202 No Default Instance defined for PluginFamily 
StructureMapBasic.IConsumer, StructureMapBasic, Version=1.0.0.0, 
Culture=neutral, PublicKeyToken=null.

At first i thought maybe the StructureMap.Config file didn't get into the new projects bin folder but that wasn't the case. It was there. Everythign compiles just fine this problem happens at runtime. I'm sure the solution is very easy but for the life of me i can't figure out whats going wrong. Any help would be MUCH appreciated.

Thanks, Ncage

A: 

I took me all friggn day to figure this out. At first i thought i was just being an idiot and i was missing something stupid. Well i was not. I thought it was related to different projects but it was not. I created a new console application that consumed my StructureMapped DLL (If just coined a term ;) ). Anyways, after trying to spend all day on this problem i FINALLY found a post that described the problem. its a freakn bug in MSTest (my project i was having problems with was created in MSTest). Xunit here i come. Here is a post that describes the issue from the same guy who created the tutorial video:

http://devlicio.us/blogs/derik%5Fwhittaker/archive/2008/07/23/mstest-why-i-hate-you-you-cause-me-too-much-friction.aspx