Domain driven design Autofac中的协方差?
我正在使用AutoFAC 2.2.4,对容器分辨率中的协方差有疑问 我的存储库有一个基本接口定义:Domain driven design Autofac中的协方差?,domain-driven-design,autofac,Domain Driven Design,Autofac,我正在使用AutoFAC 2.2.4,对容器分辨率中的协方差有疑问 我的存储库有一个基本接口定义: IRepository<T, TKey> IRepository 其中包含Find(Tkey)、FindAll()等 例如,它是这样使用的: IRepository<Catalog, int> builder.RegisterType<CatalogRepository>() .As<IRepository<Catalog, int&g
IRepository<T, TKey>
IRepository
其中包含Find(Tkey)、FindAll()等
例如,它是这样使用的:
IRepository<Catalog, int>
builder.RegisterType<CatalogRepository>()
.As<IRepository<Catalog, int>>();
IRepository
这意味着目录具有整数键。我注册了它的存储库,如下所示:
IRepository<Catalog, int>
builder.RegisterType<CatalogRepository>()
.As<IRepository<Catalog, int>>();
builder.RegisterType()
.As();
一切都很好。
后来我意识到我需要一个额外的.Find()类型,所以我定义了一个新接口:
ICatalogRepository : IRepository<Catalog, int>
{
Catalog Find(string name);
}
iCatalOperatory:IRepository
{
目录查找(字符串名称);
}
我更改了注册:
builder.RegisterType<CatalogRepository>()
.As<ICatalogRepository>();
builder.RegisterType()
.As();
但现在尝试解决IRepositorybuilder.RegisterType<CatalogRepository>()
.As<ICatalogRepository>()
.As<IRepository<Catalog, int>>();
builder.RegisterType()
.As()
.As();
让他们两个都解决。(仍然有来自其他通用实体操作工具的解析IRepository的调用,这些工具不知道派生接口。)我做错了什么吗?这是预期的行为。但是,您可以查看该功能,特别是AsImplementedInterfaces方法