【发布时间】:2013-12-20 08:55:41
【问题描述】:
我正在创建一个mvc4应用,解决方案结构如下:
这里DAO层是在Data.EntityFramework中实现的。Service层是为托管服务创建服务和servicehost。CORE层是为所有分层注册。
数据实体层是:
我正在从服务层调用 UnitOfWork,如下所示
public class CandidateService : ICandidateService
{
private readonly IUnitOfWork _unitOfWork;
public CandidateService(IUnitOfWork unitOfWork)
{
this._unitOfWork = unitOfWork;
}
//public IList<VW_CANDBASICSEARCH> GetAll()
//{
// try
// {
// var lstCandidate = _unitOfWork.Repository<VW_CANDBASICSEARCH>().All();
// var list = lstCandidate.ToList<VW_CANDBASICSEARCH>();
// return list;
// }
// catch (Exception er)
// {
// throw er;
// }
//}
public IList<VW_CANDBASICSEARCH> GetSearchCandidate(string strName, string strLocation, string strProfession, string strSkill)
{
var lstCandidate = _unitOfWork.Repository<VW_CANDBASICSEARCH>().All().ToList<VW_CANDBASICSEARCH>();
var lstSearchCan = from can in lstCandidate
where ((strName == null || strName.Length == 0 || (can.CAND_NAME).ToUpper().Contains(strName.ToUpper()))
&& (strLocation == null || strLocation.Length == 0 || can.CAND_LOCATION.Equals(strLocation))
&& (strProfession == null || strProfession.Length == 0 || can.CAND_PROFESSION.Equals(strProfession))
&& (strSkill == null || strSkill.Length == 0 || can.CAND_SKILL.Equals(strProfession)))
select can;
return lstSearchCan.ToList<VW_CANDBASICSEARCH>();
}
public TBLCANDIDATE_HEADER CreateCandidate(TBLCANDIDATE_HEADER Candidate)
{
Candidate.ObjectState = ObjectState.Added;
_unitOfWork.Repository<TBLCANDIDATE_HEADER>().Insert(Candidate);
return Candidate;
}
}
在 CORE 层中,我正在注册数据和业务,如下所示;
public class BusinessLogicServiceModule : Registry
{
public BusinessLogicServiceModule()
{
For(typeof(IHrmsRepository<>)).Use(typeof(Repository<>));
For<IUnitOfWork>().Use<UnitOfWork>();
}
}
在服务主机中,我在http://lostechies.com/jimmybogard/2008/07/30/integrating-structuremap-with-wcf/ 之后实现了这个 在 IHRMS.WEB 中,我正在 Global.asax.cs Application_start 中编写以下内容
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
ObjectFactory.Configure(x => x.AddRegistry(new BusinessLogicServiceModule()));
ObjectFactory.Configure(x => x.AddRegistry(new ControllerDependency()));
ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
}
但是当我运行它时,它给出了以下错误: 结构图异常代码:202 没有为 PluginFamily IHRMS.DAO.Infrastructure.IUnitOfWork、IHRMS.DAO、Version=1.0.0.0、Culture=neutral、PublicKeyToken=null 定义默认实例
我使用 Structuremap 作为 DI。 有人能帮帮我吗?
【问题讨论】:
标签: wcf entity-framework asp.net-mvc-4 structuremap