0
            ObjectFactory.Initialize(x =>
            {
                x.Scan(scan =>
                {
                    scan.Assembly("CloudAssembly");  // defines profile "Cloud"
                    scan.LookForRegistries();
                });

                x.Profile("Local", cfg =>
                {
                    cfg.For<ICloudStorage>().
                        Use(() =>
                            new LocalStorage(HttpContext.Current.Server.MapPath("~")));

                });
           });

然后我尝试将其设置为“本地”配置文件,以便 ICloudStorage 解析为 LocalStorage。

        ObjectFactory.Container.SetDefaultsToProfile("Local");
        ObjectFactory.Profile = "Local";

然后在激活依赖于 ICloudStorage 的对象时出现此异常:

StructureMap Exception Code:  202
No Default Instance defined for PluginFamily ICloudStorage, AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

我对个人资料做错了吗?我查看了 whatDoIHave 的输出,一切看起来都配置正确。

这是“whatDoIHave”的相关部分:

ICloudStorage (MyLibrary.ICloudStorage)                         Default Instance for Profile Local          Instance is created by Func<object> function:  System.Func`2[StructureMap.IContext,MyLibrary.ICloudStorage]                                                                                                                         
Scoped as:  Transient

                                                                                  Default Instance for Profile Local          Instance is created by Func<object> function:  System.Func`2[StructureMap.IContext,MyLibrary.ICloudStorage]                                                                                                                         
                                                                                  Default Instance for Profile Cloud     Configured Instance of CloudProviders.CloudStorage, CloudProviders, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null  
4

1 回答 1

0

我只是删除了我在 Initialize 方法之后直接调用的 ObjectFactory.Container.SetDefaultsToProfile("Local") 以使用配置文件...

  <StructureMap DefaultProfile="Local">

  </StructureMap>

现在它工作正常......

于 2013-10-16T15:17:11.960 回答