2013-12-20 43 views
0

我創建一個mvc4 application.The解決方案的結構下面給出適用於所有分層註冊。Structuremap與WCF和的EntityFramework

enter image description here

數據實體層是:

enter image description here

我從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。 有人可以幫我嗎?

回答

0

你的配置對我來說很好看。

我通常只針對通過執行以下這些曖昧structuremap錯誤:

  • 驗證您的注入類有:
    • 公共構造
    • 施工參數的依賴也已在註冊表中定義
  • 逐步完成'建立'工作流程
    • 確保依存關係被定義,他們被稱爲前爲
  • 確保AssertConfigurationIsValid和關閉的ObjectFactory WhatDoIHave方法來目視確認您擁有有效的依賴配置

大部分的問題都解決了在工作流驗證步驟中,如果配置了依賴關係,那麼在'結構映射'被詢問後會拋出202錯誤。

也只是爲了確認IUnitOfWork被配置和IUnitOfWork依賴關係是相同的對象權利(IE:它們是相同的命名空間,什麼不是)?

對不起,我目前沒有答案,但如果你有更多的信息,我會很樂意提供幫助。

謝謝, wm