Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 结构映射异常202_Asp.net Mvc_Wcf_Asp.net Mvc 4_Structuremap_Wcf Extensions - Fatal编程技术网

Asp.net mvc 结构映射异常202

Asp.net mvc 结构映射异常202,asp.net-mvc,wcf,asp.net-mvc-4,structuremap,wcf-extensions,Asp.net Mvc,Wcf,Asp.net Mvc 4,Structuremap,Wcf Extensions,我在WCF服务和MVC 4应用程序上使用StructureMap,我在这两个应用程序上都进行了配置,但一旦运行应用程序,我会收到以下异常: StructureMap异常代码:202未为定义默认实例 插入式家庭 LookupsRepositories.Lookups.ILookupRepository`1[[JE.Domain.Lookups.Status, JE.Domain,版本=1.0.0.0,区域性=中立,PublicKeyToken=null], LookupsRepositories,

我在WCF服务和MVC 4应用程序上使用StructureMap,我在这两个应用程序上都进行了配置,但一旦运行应用程序,我会收到以下异常:

StructureMap异常代码:202未为定义默认实例 插入式家庭 LookupsRepositories.Lookups.ILookupRepository`1[[JE.Domain.Lookups.Status, JE.Domain,版本=1.0.0.0,区域性=中立,PublicKeyToken=null], LookupsRepositories,版本=1.0.0.0,区域性=neutral, PublicKeyToken=null

LookupRepository
是一个抽象类,一个泛型类,我就是这样注册它的:

For(typeof(ILookupRepository<>)).Use(typeof(LookupRepository<>));
For<ILookupUnitOfWork>().Use<LookupUnitOfWork>();
Scan(s =>
        {
            s.AssemblyContainingType(typeof(LookupRepository<>));
            s.ConnectImplementationsToTypesClosing(typeof(ILookupRepository<>));
        });
但我还是有例外。知道为什么吗


注:StructureMap版本2.6.4.0此处的答案与以下信息有关:

LookupRepository
是一个抽象类

因此,要使其运行,我们必须确保:

// abstract base
public class LookupRepository<T> : ILookupRepository<T>
// implementation
public class StatusRepository : LookupRepository<Status> { ... }

...
// mapping
// do not use this
// r.For(typeof(ILookupRepository<>)).Use(typeof(LookupRepository<>));
// just this
r.Scan(s =>
{
    s.AssemblyContainingType(typeof(LookupRepository<>));
    s.ConnectImplementationsToTypesClosing(typeof(ILookupRepository<>));
});


...
// init - will return new StatusRepository();
ObjectFactory.GetInstance<ILookupRepository<Status>>(); 
//抽象基
公共类LookupRepository:ILookupRepository
//实施
公共类StatusRepository:LookupRepository{…}
...
//映射
//不要用这个
//r.For(typeof(ilookuppository))。用法(typeof(LookupRepository));
//就这个
r、 扫描(s=>
{
s、 AssemblyContainingType(typeof(LookupRepository));
s、 连接实现到类型关闭(类型关闭(ILookupRepository));
});
...
//init-将返回新的StatusRepository();
GetInstance();
如果基类不是抽象的,那么也可以这样做:

// non abstract
public class LookupRepository<T> : ILookupRepository<T>

...
// mapping
r.For(typeof(ILookupRepository<>)).Use(typeof(LookupRepository<>));

...
// init - will return new LookupRepository<Status>();
ObjectFactory.GetInstance<ILookupRepository<Status>>(); 
//非抽象
公共类LookupRepository:ILookupRepository
...
//映射
r、 For(typeof(ILookupRepository))。使用(typeof(LookupRepository));
...
//init-将返回新的LookupRepository();
GetInstance();
// non abstract
public class LookupRepository<T> : ILookupRepository<T>

...
// mapping
r.For(typeof(ILookupRepository<>)).Use(typeof(LookupRepository<>));

...
// init - will return new LookupRepository<Status>();
ObjectFactory.GetInstance<ILookupRepository<Status>>();