Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/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
Asp.net MEF错误消息-VS2010_Asp.net_Visual Studio 2010_Mef - Fatal编程技术网

Asp.net MEF错误消息-VS2010

Asp.net MEF错误消息-VS2010,asp.net,visual-studio-2010,mef,Asp.net,Visual Studio 2010,Mef,有人能帮我解释一下这个错误信息吗 system.componentmodel.composition.changerejectedexception The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced a single composition error. The root cause is provid

有人能帮我解释一下这个错误信息吗

system.componentmodel.composition.changerejectedexception

The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced a single composition error. 
The root cause is provided below. Review the CompositionException.Errors property for more detailed information.

1) No exports were found that match the constraint: 
ContractName    Itok.BusinessLogic.Interfaces.IFolderService
RequiredTypeIdentity    Itok.BusinessLogic.Interfaces.IFolderService

Resulting in: Cannot set import 'Itok.Web.Photos.Presenters.DefaultPresenter._folderService (ContractName="Itok.BusinessLogic.Interfaces.IFolderService")' on part 'Itok.Web.Photos.Presenters.DefaultPresenter'.

Element: Itok.Web.Photos.Presenters.DefaultPresenter._folderService (ContractName="Itok.BusinessLogic.Interfaces.IFolderService") --> Itok.Web.Photos.Presenters.DefaultPresenter
以下是IFolderService.cs:

using System;
using System.Collections.Generic;
using Itok.Entities;

namespace Itok.BusinessLogic.Interfaces
{
    public interface IFolderService
    {
        List<Folder> GetFriendsFolders(Int32 AccountID);
        void DeleteFolder(Folder folder);
        List<Folder> GetFoldersByAccountID(Int32 AccountID);
        Folder GetFolderByID(Int64 FolderID);
        Int64 SaveFolder(Folder folder);
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Itok.BusinessLogic.Interfaces;
using System.ComponentModel.Composition;
using Itok.DataAccess.Interfaces;
using Itok.Common;
using Itok.DataAccess;
using Itok.Interfaces;
using Itok.Entities;

namespace Itok.BusinessLogic
{    
    [Export(typeof(IFolderService))]    
    [Export(typeof(ICache))]
    public class FolderService : IFolderService
    {
        [Import]
        private IFriendRepository _friendRepository;
        [Import]
        private IFolderRepository _folderRepository;
        [Import]
        private ICache _cacheService;

        public FolderService()
        {
            MEFManager.Compose(this);
        }

        public List<Folder> GetFriendsFolders(Int32 AccountID)
        {
            List<Friend> friends = _friendRepository.GetFriendsByAccountID(AccountID);
            List<Folder> folders = _folderRepository.GetFriendsFolders(friends);
            folders.OrderBy(f => f.CreateDate).Reverse();
            return folders;
        }

         public void DeleteFolder(Folder folder)
        {   
            if (_cacheService.Exists(folder.AccountID.ToString()))
            {
                _cacheService.Delete(folder.AccountID.ToString());
            }

            _folderRepository.DeleteFolder(folder);
        }

        public List<Folder> GetFoldersByAccountID(int AccountID)
        {        
            List<Folder> cachedFolders = _cacheService.Get(AccountID.ToString()) as List<Folder>;
            if (cachedFolders != null)
            {
                return cachedFolders;
            }
            else
            {
                cachedFolders = _folderRepository.GetFoldersByAccountID(AccountID);
                _cacheService.Set(AccountID.ToString(), cachedFolders);
                return cachedFolders;
            }
        }

        public Folder GetFolderByID(Int64 FolderID)
        {
            return _folderRepository.GetFolderByID(FolderID);
        }

        public Int64 SaveFolder(Folder folder)
        {
            return _folderRepository.SaveFolder(folder);
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用Itok.Entities;
命名空间Itok.BusinessLogic.Interfaces
{
公共接口IFolderService
{
列出GetFriendsFolders(Int32 AccountID);
作废删除文件夹(文件夹);
列出GetFoldersByAccountID(Int32 AccountID);
文件夹GetFolderByID(Int64 FolderID);
Int64保存文件夹(文件夹);
}
}
这是导出类定义FolderService.cs:

using System;
using System.Collections.Generic;
using Itok.Entities;

namespace Itok.BusinessLogic.Interfaces
{
    public interface IFolderService
    {
        List<Folder> GetFriendsFolders(Int32 AccountID);
        void DeleteFolder(Folder folder);
        List<Folder> GetFoldersByAccountID(Int32 AccountID);
        Folder GetFolderByID(Int64 FolderID);
        Int64 SaveFolder(Folder folder);
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Itok.BusinessLogic.Interfaces;
using System.ComponentModel.Composition;
using Itok.DataAccess.Interfaces;
using Itok.Common;
using Itok.DataAccess;
using Itok.Interfaces;
using Itok.Entities;

namespace Itok.BusinessLogic
{    
    [Export(typeof(IFolderService))]    
    [Export(typeof(ICache))]
    public class FolderService : IFolderService
    {
        [Import]
        private IFriendRepository _friendRepository;
        [Import]
        private IFolderRepository _folderRepository;
        [Import]
        private ICache _cacheService;

        public FolderService()
        {
            MEFManager.Compose(this);
        }

        public List<Folder> GetFriendsFolders(Int32 AccountID)
        {
            List<Friend> friends = _friendRepository.GetFriendsByAccountID(AccountID);
            List<Folder> folders = _folderRepository.GetFriendsFolders(friends);
            folders.OrderBy(f => f.CreateDate).Reverse();
            return folders;
        }

         public void DeleteFolder(Folder folder)
        {   
            if (_cacheService.Exists(folder.AccountID.ToString()))
            {
                _cacheService.Delete(folder.AccountID.ToString());
            }

            _folderRepository.DeleteFolder(folder);
        }

        public List<Folder> GetFoldersByAccountID(int AccountID)
        {        
            List<Folder> cachedFolders = _cacheService.Get(AccountID.ToString()) as List<Folder>;
            if (cachedFolders != null)
            {
                return cachedFolders;
            }
            else
            {
                cachedFolders = _folderRepository.GetFoldersByAccountID(AccountID);
                _cacheService.Set(AccountID.ToString(), cachedFolders);
                return cachedFolders;
            }
        }

        public Folder GetFolderByID(Int64 FolderID)
        {
            return _folderRepository.GetFolderByID(FolderID);
        }

        public Int64 SaveFolder(Folder folder)
        {
            return _folderRepository.SaveFolder(folder);
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用Itok.BusinessLogic.Interfaces;
使用System.ComponentModel.Composition;
使用Itok.DataAccess.Interfaces;
使用Itok.Common;
使用Itok.DataAccess;
使用Itok.接口;
使用Itok.Entities;
名称空间Itok.BusinessLogic
{    
[导出(类型(IFolderService))]
[导出(类型(ICache))]
公共类FolderService:IFolderService
{
[进口]
私人IFriendRepository\u friendRepository;
[进口]
私人IFolderRepository\u folderRepository;
[进口]
私人ICache_缓存服务;
公共文件夹服务()
{
MEFManager.Compose(这个);
}
公共列表GetFriendsFolders(Int32 AccountID)
{
List friends=\u friendsrepository.GetFriendsByAccountID(AccountID);
列表文件夹=_folderRepository.GetFriendsFolders(朋友);
folders.OrderBy(f=>f.CreateDate).Reverse();
返回文件夹;
}
公用作废删除文件夹(文件夹)
{   
如果(_cacheService.Exists(folder.AccountID.ToString()))
{
_cacheService.Delete(folder.AccountID.ToString());
}
_DeleteFolder(文件夹);
}
公共列表GetFoldersByAccountID(int AccountID)
{        
List cachedFolders=\u cacheService.Get(AccountID.ToString())作为列表;
if(cachedFolders!=null)
{
返回缓存文件夹;
}
其他的
{
cachedFolders=\u folderRepository.GetFoldersByAccountID(AccountID);
_cacheService.Set(AccountID.ToString(),cachedFolders);
返回缓存文件夹;
}
}
公用文件夹GetFolderByID(Int64 FolderID)
{
return\u folderRepository.GetFolderByID(FolderID);
}
公用Int64保存文件夹(文件夹)
{
返回_folderRepository.SaveFolder(文件夹);
}
}
}

在此之前,我感谢您为我节省了时间。

错误消息表示MEF正在查找使用接口
IFolderService
导出的类,但容器中没有


要对此进行调查,首先检查是否有导出该接口的类,如果有,然后检查该类是否由容器拾取,第三,如果两者都不能解决问题,查看使用接口
IFolderService
导出的类是否有其他无法满足的导入。

错误消息表示MEF正在查找使用接口
IFolderService
导出的类,但容器中没有


要对此进行调查,首先检查是否有导出该接口的类,如果有,然后检查该类是否由容器拾取,第三,如果两者都不能解决问题,查看使用接口
IFolderService
导出的类是否有其他无法满足的导入。

最后,我找到了问题的解决方案。它与MEF所指的IFolderService没有直接关系。该应用程序依赖于业务逻辑中的组件(FolderService),而该组件又依赖于接口ICache和实现包装器Cache.cs。ICache由合同名Itok.Interfaces.ICache指定,已导出四次(仅一次导入)。在我尝试扩展解决方案时,没有注意到这一点。MEF无法判断要使用哪个导出。真正的问题是,MEF指向的是链条上方的二级

感谢TomDoesCode关注这个问题,我希望这将帮助其他遇到类似问题的人

这个问题的长期解决方案是,如果您有多个出口可以满足一个进口,那么您可能有两个选择:

一) 用[ImportMany]更改[Import]。然后在运行时,决定将哪个导入用于契约。问问自己,是选择第一个可用的,还是一次随机使用一个


二) 将[ImportMany]与元数据结合使用,以决定使用哪个导入。

最后,我找到了问题的解决方案。它与MEF所指的IFolderService没有直接关系。该应用程序依赖于业务逻辑中的组件(FolderService),而该组件又依赖于接口ICache和实现包装器Cache.cs。ICache由合同名Itok.Interfaces.ICache指定,已导出四次(仅一次导入)。在我尝试扩展解决方案时,没有注意到这一点。MEF无法判断要使用哪个导出。真正的问题是,MEF指向的是链条上方的二级

感谢TomDoesCode关注这个问题,我希望这将帮助其他遇到类似问题的人

这个问题的长期解决方案是,如果您有多个出口可以满足一个进口,那么您可能有两个选择:

一) 用[ImportMany]更改[Import]。然后在运行时,决定要将哪个导入用于co