1

嗨,我在我的项目中使用了 UOW 和存储库模式,并且创建了以下代码:

// Interfaces
public interface IUnitOfWork : IDisposable
{
    IGenericRepository<Company> CompanyRepository { get; }
    void Commit();
}

public interface IEFUOW_Company : IUnitOfWork
{
    bool CreateCompanyForUser(RegisterModel model, string userName);
}

// Implementation
public class EFUOW_Company : EfUnitOfWork
{
    public EFUOW_Company()
    {
    }
}

public class EfUnitOfWork : Disposable, IUnitOfWork
{
    private DALDbContext _dataContext;
    private EfGenericRepository<Company> _companyRepo;
    public DbSet<Company> Companies { get; set; }

    public EfUnitOfWork()
    {
        _companyRepo = null;
    }
}

// Unity Registration
container.RegisterType<IUnitOfWork, EfUnitOfWork>(new HttpContextLifetimeManager<IUnitOfWork>());
         .RegisterType<IEFUOW_Company, EFUOW_Company>(new HttpContextLifetimeManager<IEFUOW_Company>());


// Error Message @ Compile

Error   105 The type 'DataAccessLayer.UnitOfWork.EFUOW_Company' cannot be used as type parameter 'TTo' in the generic type or method 
'Microsoft.Practices.Unity.UnityContainerExtensions.RegisterType<TFrom,TTo>(Microsoft.Practices.Unity.IUnityContainer, Microsoft.Practices.Unity.L
ifetimeManager, params Microsoft.Practices.Unity.InjectionMember[])'. There is no implicit reference conversion from '
DataAccessLayer.UnitOfWork.EFUOW_Company' to 'DataAccessLayer.UnitOfWork.IEFUOW_Company'.

我无法弄清楚为什么它抱怨转换,因为我是 Unity 的新手,这是我第一次尝试构建这种类型的逻辑。

我希望能够创建不同的基于接口/实现,这样我就可以在它的实现IUnitOfWork中重用代码IUnitOfworkEfUnitOfWork

提前致谢

4

1 回答 1

2

efuow_company 类没有实现 iefuow_company 接口。

于 2013-05-31T09:12:24.660 回答