tags:

views:

253

answers:

2

I'm trying to get started with Structure Map. I'm using version 2.5.3.

I've built a simple boot strapper, but I can't get it to compile. I get the error:

'StructureMap.Configuration.DSL.Expressions.CreatePluginFamilyExpression' does not contain a definition for 'WithCtorArg' and no extension method 'WithCtorArg' accepting a first argument of type 'StructureMap.Configuration.DSL.Expressions.CreatePluginFamilyExpression' could be found (are you missing a using directive or an assembly reference?)

What's the am I missing?

the code I'm try to compile is here:

using DomainModel.Abstract;
using DomainModel.Concrete;
using StructureMap;
using StructureMap.Pipeline; //The only WithCtorArg methods I can find are in this namespace, it didn't help.

namespace WebUI
{
public class ContainerBootstrapper
{
 public static void BootstrapStructureMap()
 {
  // Initialize the static ObjectFactory container
  ObjectFactory.Initialize(x =>
  {
   x.ForRequestedType<IProductsRepository>()
    .TheDefaultIsConcreteType<SqlProductsRepository>()
       .WithCtorArg("connectionString")
       .EqualToAppSetting("SqlConnection");
  });
 }
}
}
A: 

If your class has a non default constructor with simple type arguments like string, int, etc... you can try this:

x.ForRequestedType<IProductsRepository>()
 .TheDefault
 .Is
 .OfConcreteType<SqlProductsRepository>()
 .WithCtorArg("connectionString")
 .EqualToAppSetting("SqlConnection");
Darin Dimitrov
A: 

I've ran into a similar issue.

If you're using the generic version of ForRequestedType you have to do as darin suggested and use the TheDefault.Is.OfConcreteType syntax

If you're using the non-generic version of ForRequestedType you can do it like so:

x.ForRequestedType(typeof (ProductsRepository))
 .TheDefaultIsConcreteType(typeof(SqlProductsRepository))
 .WithCtorArg("connectionString")
 .EqualToAppSetting("SqlConnection");
Andrew Hanson