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.

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

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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.

        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.