views:

64

answers:

1

Hello Everyone,

I just started digging into StructureMap and am running into some problems getting my config up-and-running. It seems that when I try to register Plugins in their respective PluginFamily they aren't being found by StructureMap. I've gone over many examples on the web but can't seem to see where I am going wrong.

Can another set of eyes see what my problem is?

Thank you so much for your time.

--Charly

<configuration>

 <configSections>
   <section name="StructureMap"
            type="StructureMap.Configuration.StructureMapConfigurationSection, StructureMap"/>
 </configSections >

 <StructureMap>

   <Assembly Name="Domain.Model" />

   <!-- ICustomField -->
   <PluginFamily Type="Domain.Model.CustomFields.ICustomField"
                 Assembly="Domain.Model"
                 DefaultKey="String">

     <Plugin Type="Domain.Model.CustomFields.StringCustomField"
             Assembly="Domain.Model"
             ConcreteKey="String" />

     <Plugin Type="Domain.Model.CustomFields.DateTimeCustomField"
             Assembly="Domain.Model"
             ConcreteKey="DateTime" />

     <Plugin Type="Domain.Model.CustomFields.BooleanCustomField"
             Assembly="Domain.Model"
             ConcreteKey="Boolean" />

     <Plugin Type="Domain.Model.CustomFields.IntegerCustomField"
             Assembly="Domain.Model"
             ConcreteKey="Integer" />

     <Plugin Type="Domain.Model.CustomFields.DecimalCustomField"
             Assembly="Domain.Model"
             ConcreteKey="Decimal" />

   </PluginFamily>

 </StructureMap>

</configuration>


[TestFixture]
public class BooleanCustomFieldTest
{
       [SetUp]
       public void SetUp()
       {
               log4net.Config.XmlConfigurator.Configure();

               ObjectFactory.Initialize(x =>
                               {
                                   x.PullConfigurationFromAppConfig = true;
                               });
       }

       [Test]
       public void StructureMapCanCreateAnInstanceOfBooleanCustomField()
       {
               ICustomField field =
ObjectFactory.GetNamedInstance<ICustomField>("Boolean");

               Assert.IsNotNull(field);
               Assert.IsInstanceOf<BooleanCustomField>(field);
       }
}
A: 

Charly, I took the code/config you supplied (I had to manually create the instances of ICustomField and the subsequent concrete types as you didn't supply them in the example code)

Maybe you could supply the code for your model/interface declarations?

The test supplied passes for all custom field types in the example I constructed.

One thing you might want to try is ObjectFactory.WhatDoIHave() which will show you all of the registered types within the container.

If you want me to send you the working example of your code to see if there are any other differences, give me a shout.

btw - I used 2.6.2.160 direct from the team city build server.

Gareth Williams
Gareth, if you could send me what you put together I think that would be easiest. Hopefully I could spot what I am doing wrong then. I'm pretty new to Stack Overflow. What's the best way to get you my email address?
CreepingCharly
Thanks for taking the extra time putting an example together. I really appreciate it.
CreepingCharly
Charly, you can email me at [email protected] if you like.
Gareth Williams