如何配置Unity容器以消除EntityContext的构造:

时间:2011-06-10 14:13:02

标签: unity-container ioc-container

ForEach(repository =>
{
    var objectContextServiceType = typeof(BaseObjectContext<>)
        .MakeGenericType(repository.ObjectContextType);

        container.RegisterType(objectContextServiceType, 
        new PerExecutionContextLifetimeManager());

    var repositoryServiceType = typeof(IRepository<>)
        .MakeGenericType(repository.DomainType);

    var repositoryImplementation = typeof(EntityRepository<,>)
        .MakeGenericType(repository.DomainType,
            repository.ObjectContextType);

    container.RegisterType(repositoryServiceType,
        repositoryImplementation, 
        new TransientLifetimeManager());
})

当Unity尝试解析EntityContext时,我收到错误:无法消除实体上下文创建的歧义

0 个答案:

没有答案