我創建一個mvc4 application.The解決方案的結構下面給出適用於所有分層註冊。Structuremap與WCF和的EntityFramework
數據實體層是:
我從servicelayer調用的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;
}
}
核心層,我註冊數據和業務類似下面的;
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();
}
但是當我運行它給以下錯誤: StructureMap異常代碼:202 沒有爲PluginFamily定義的默認實例IHRMS.DAO.Infrastructure.IUnitOfWork,IHRMS.DAO,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null
我正在使用Structuremap作爲DI。 有人可以幫我嗎?