0
我得到了這個問題與控制器: 嘗試創建類型'* .WebMvc.Controllers.HomeController'類型的控制器時發生錯誤。確保控制器有一個無參數的公共構造函數。無參數的公共構造函數 - Unity
public class HomeController : BaseController
{
#region Fields
private readonly INewsService _newsService;
#endregion
#region Constructors
public HomeController(INewsService newsService)
{
this._newsService = newsService;
}
#endregion
#region unilities
public ActionResult Index()
{
return View();
}
#endregion
}
public interface INewsService : IEntityService<proNew>
{
proNew GetById(int Id);
}
public interface IEntityService<T> : IService where T : class
{
void Create(T entity);
void Delete(T entity);
IEnumerable<T> GetAll();
void Update(T entity);
}
public abstract class EntityService<T> : IEntityService<T> where T : class
{
IUnitOfWork _unitOfWork;
IGenericRepository<T> _repository;
public EntityService(IUnitOfWork unitOfWork, IGenericRepository<T> repository)
{
_unitOfWork = unitOfWork;
_repository = repository;
}
public virtual void Create(T entity)
{
if (entity == null)
{
throw new ArgumentNullException("entity");
}
_repository.Add(entity);
_unitOfWork.Commit();
}
public virtual void Update(T entity)
{
if (entity == null) throw new ArgumentNullException("entity");
_repository.Edit(entity);
_unitOfWork.Commit();
}
public virtual void Delete(T entity)
{
if (entity == null) throw new ArgumentNullException("entity");
_repository.Delete(entity);
_unitOfWork.Commit();
}
public virtual IEnumerable<T> GetAll()
{
return _repository.GetAll();
}
}
public class NewsService : EntityService<proNew>, INewsService
{
IUnitOfWork _unitOfWork;
INewsRepository _countryRepository;
public NewsService(IUnitOfWork unitOfWork, INewsRepository newsRepository) : base(unitOfWork, newsRepository)
{
_unitOfWork = unitOfWork;
_countryRepository = newsRepository;
}
public proNew GetById(int Id)
{
return _countryRepository.GetById(Id);
}
}
你在這裏使用依賴注入嗎? – 2015-02-10 12:41:10