我尝试从aspnetboilerplate开始编写代码。
调用WindsorContainer
类函数
public void Register(Type type, Type impl, DependencyLifeStyle lifeStyle = DependencyLifeStyle.Singleton)
看起来像这样:
iocManager.Register(
typeof(IRepository<,>).MakeGenericType(entityType, primaryKeyType),
typeof(EfRepositoryBase<,,>).MakeGenericType(dbContextType, entityType, primaryKeyType),
DependencyLifeStyle.Transient
);
支持类型是:
[System.RuntimeType] = {Name = "IRepository`2" FullName = "Abp.Domain.Repositories.IRepository`2"}
和
base = {Name = "EfRepositoryBase`3" FullName = null}
我们可以看到由MakeGenericType()
具体类型的FullName
实例化的是null
。
班级EfRepositoryBase3
如下所示:
public class EfRepositoryBase<TDbContext, TEntity, TPrimaryKey> : IRepository<TEntity, TPrimaryKey>
where TEntity : class, IEntity<TPrimaryKey>
where TDbContext : DbContext
{
... CRUD methods...
}
为什么FullName
null
是{{1}}以及如何克服这个问题?
答案 0 :(得分:1)
FullName可以返回null
Type的完全限定名称,包括。的名称空间 键入但不是组件;如果当前实例表示,则返回null 泛型类型参数,数组类型,指针类型或byref类型 基于类型参数或非泛型的泛型类型 类型定义但包含未解析的类型参数。
您可以使用GetGenericTypeDefinition
方法获取非空名称。