1

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.

Diego
  • 11
  • 2
  • private static void InitializeStructureMap(IInitializationExpression x) { x.Scan(y => { y.Assembly("MVCPoco.Core"); y.Assembly("MVCPoco.Data"); y.With(); }); I'm using that code to make use of the default name convention... maybe i'm doing something wrong. – Diego Dec 22 '09 at 13:19
  • I'm using SM 2.5.2 these methods noes not exists in my current context x.For().Use(); y.With(new SingleImplementationScanner()); – Diego Dec 22 '09 at 14:14

3 Answers3

1

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
  • 8,527
  • 2
  • 31
  • 40
0

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
  • 10,666
  • 8
  • 48
  • 71
0

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
  • 11
  • 2