开发者

Problem Implementing Simple StructureMap Config

开发者 https://www.devze.com 2023-01-20 01:20 出处:网络
I just started digging into StructureMap and am running into some problems getting myconfig up-and-running.It seems that when I try to register Plugins in their respective

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" />

   <!-- IC开发者_运维问答ustomField -->
   <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);
       }
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消