views:

254

answers:

3

Hi, I'm getting an error:

StructureMap Exception Code: 202 No Default Instance defined for PluginFamily MVCPoco.Services.IService, MVCPoco.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Line 96:         {
Line 97:             Type controllerType = base.GetControllerType(context, controllerName);
Line 98:             return ObjectFactory.GetInstance(controllerType) as IController;
Line 99:         }
Line 100:    }

the error occurs in line 98

Any ideas? I'm using asp.net mvc 2 preview 2 that ships with visual studio 2010.

A: 

You must register the types to be injected at application start within the ObjectFactory.Configure function. Check out the documents over on Structure Map's site for Configuring your IOC Container.

Andrew

REA_ANDREW
+1  A: 

The controller you are trying to instantiate has a constructor dependency on IService. You have to make sure that you register a concrete implementation of IService when you configure StructureMap. The DefaultConventionScanner will only register implementations that have the same name as their interface (without the leading I). So, unless your implementation of IService is named Service, it will not be registered automatically. To register it explicitly, add something like this to your inititalization script:

x.For<IService>().Use<MyService>();

Alternatively, if you are running StructureMap from the latest source code, you can make use of the SingleImplementationScanner in your Scan() expression:

y.With(new SingleImplementationScanner());

and that will automatically register concrete types if they are the only implementation of an interface in the scanned code, regardless of name.

Joshua Flanagan
A: 

Well, i've set up correctly the structuremap i've just switched to the method

 public static void Configure()
        {
            ObjectFactory.Initialize(x =>

            x.AddRegistry(new IOCRegistry())); // in here i have registered my dependencies with for method.

        }
Diego