public class RepositoryRegistry : Registry
{
public RepositoryRegistry()
{
Scan(x =>
{
x.Assembly("MyApp.Data");
x.TheCallingAssembly();
x.WithDefaultConventions();
x.AddAllTypesOf(typeof(ILookupRepo<>));
});
var tmp = ObjectFactory.GetInstance<ILookupRepo<User>>();
Debug.WriteLine(ObjectFactory.WhatDoIHave());
}
}
出现此错误:
{"StructureMap Exception Code: 202 No Default Instance defined for PluginFamily MyApp.Data.Repositories.Lookup.ILookupRepo`1[[MyApp.Data.Context.User, MyApp.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], TolMobile.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"}
StructureMap似乎无法解析IAnything<T>
。这有什么理由停止工作吗?我在另一个项目中以完全相同的方式使用它,它解决了。唯一的区别是我现在使用的StructureMap版本更新......
答案 0 :(得分:0)
这不是StructureMap问题 - 没有类型继承自ILookupRepo<>
。
这是一个开放的泛型类型,而不是基类型!如果要查找关于ILookupRepo<>
的类型,则需要像这样扫描:
Scan(x =>
{
x.Assembly("MyApp.Data");
x.TheCallingAssembly();
x.WithDefaultConventions();
x.ConnectImplementationsToTypesClosing(typeof(ILookupRepo<>));
});