Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有wcf和Entityframework的Structuremap_Wcf_Entity Framework_Asp.net Mvc 4_Structuremap - Fatal编程技术网

带有wcf和Entityframework的Structuremap

带有wcf和Entityframework的Structuremap,wcf,entity-framework,asp.net-mvc-4,structuremap,Wcf,Entity Framework,Asp.net Mvc 4,Structuremap,我正在创建一个mvc4应用程序。解决方案结构如下所示: 这里DAO层在Data.EntityFramework中实现。服务层为托管服务创建服务和servicehost。核心层用于所有分层注册 数据实体层为: 我正在从servicelayer调用UnitOfWork,如下所示 public class CandidateService : ICandidateService { private readonly IUnitOfWork _unitOfWork

我正在创建一个mvc4应用程序。解决方案结构如下所示:

这里DAO层在Data.EntityFramework中实现。服务层为托管服务创建服务和servicehost。核心层用于所有分层注册

数据实体层为:

我正在从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;

            }
        }
但当我运行时,它会出现以下错误: StructureMap异常代码:202 没有为PluginFamily IHRMS.DAO.Infrastructure.IUnitOfWork、IHRMS.DAO、版本=1.0.0.0、区域性=中立、PublicKeyToken=null定义默认实例

我使用Structuremap作为DI。
有人能帮我吗?

我觉得你的配置不错

我通常通过执行以下操作来解决这些不明确的structuremap错误:

验证注入的类是否具有: 公共建设者 构造参数依赖项也已在注册表中定义 逐步完成“构建”工作流 确保在调用依赖项之前已定义它们 确保ObjectFactory中的AssertConfigurationsValid和WhatDihave方法可以直观地确认您具有有效的依赖项配置 大多数问题都是在工作流验证步骤中解决的,如果请求structuremap“after”配置依赖项,则会抛出202错误

还要确认正在配置的IUnitOfWork和IUnitOfWork依赖项是同一个对象,对吗?即:它们是同一名称空间,什么不是

对不起,我现在没有答案,但是如果你有更多的信息,我很乐意帮助你

谢谢, 西医

public class BusinessLogicServiceModule : Registry
        {


            public BusinessLogicServiceModule()
            {
                For(typeof(IHrmsRepository<>)).Use(typeof(Repository<>));
                For<IUnitOfWork>().Use<UnitOfWork>();


            }
        }
 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();
            }