Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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 mvc 4 温莎城堡登记册:Can';t创建组件';X.YService';因为它需要满足依赖关系_Asp.net Mvc 4_C# 4.0_Repository_Entity Framework 5_Castle Windsor - Fatal编程技术网

Asp.net mvc 4 温莎城堡登记册:Can';t创建组件';X.YService';因为它需要满足依赖关系

Asp.net mvc 4 温莎城堡登记册:Can';t创建组件';X.YService';因为它需要满足依赖关系,asp.net-mvc-4,c#-4.0,repository,entity-framework-5,castle-windsor,Asp.net Mvc 4,C# 4.0,Repository,Entity Framework 5,Castle Windsor,这应该是一个普遍的问题,我已经搜索了,但还没有找到任何解决方案,如果是一个重复,请给我指出适当的链接。 所以,我有一个通用存储库来支持几个实体,我像下面一样注册它 控制器:这是我的控制器部分 public class XController : Controller { private ILegendsService _legendsService; public LegendsContr

这应该是一个普遍的问题,我已经搜索了,但还没有找到任何解决方案,如果是一个重复,请给我指出适当的链接。 所以,我有一个通用存储库来支持几个实体,我像下面一样注册它

控制器:这是我的控制器部分

        public class XController : Controller
            {

                private  ILegendsService _legendsService;
                public LegendsController(ILegendsService legendsService)
                {
                    _legendsService = legendsService;
                }
        } 
服务:这是我的传奇服务区

         public class LegendsService:ILegendsService
            {
                private readonly IRepositoryFactory<Legends, int> _legends;
                private readonly IUnitOfWork _unitOfWork;
                private readonly IDiObjectMapper _mapper;
                public LegendsService(IRepositoryFactory<Legends, int> 
                    legendsInfo
                    , IUnitOfWork unitOfWork
                    , IDiObjectMapper mapper)
                {
                    _legends = legendsInfo;
                    _unitOfWork = unitOfWork;
                    _mapper = mapper;


                }
        }
DIObjectMapper:这是我的DIObjectMapper

 public interface IDiObjectMapper
    {
        TDestination Map<TSource, TDestination>(TSource source)
            where TSource : class
            where TDestination : class;

        TDestination Map<TSource, TDestination>(TSource source, TDestination destination)
            where TSource : class
            where TDestination : class;
    }

    public class DiObjectMapper : IDiObjectMapper
    {
        public TDestination Map<TSource, TDestination>(TSource source)
            where TSource : class
            where TDestination : class
        {
            return AutoMapperSetup.Mapper.Map<TSource, TDestination>(source);
        }

        public TDestination Map<TSource, TDestination>(TSource source, TDestination destination)
            where TSource : class
            where TDestination : class
        {
            return AutoMapperSetup.Mapper.Map(source, destination);
        }
    }
公共接口idObjectMapper
{
t目标地图(t来源)
where TSource:class
其中t目标:类;
TDestination映射(TSource-source,TDestination-destination-destination)
where TSource:class
其中t目标:类;
}
公共类DiObjectMapper:idObjectMapper
{
公共TDestination地图(TSource来源)
where TSource:class
目的地:班级
{
返回AutoMapperSetup.Mapper.Map(源);
}
公共TDestination地图(T源源、TDestination目的地)
where TSource:class
目的地:班级
{
返回AutoMapperSetup.Mapper.Map(源、目标);
}
}
温莎城堡:这是温莎城堡集装箱登记区

   container.Register(Component.For<IDisposable> 
    ().ImplementedBy<IDatabaseFactory>().LifestylePerWebRequest());
     container.Register(Component.For<IRepository<Legends, int>> 
   ().ImplementedBy<Repository<Legends, int>> 
   ().LifestylePerWebRequest());
    container.Register(Component.For<ILegendsService> 
   ().ImplementedBy<LegendsService>().LifestylePerWebRequest());
        container.Register(Component.For<IDatabaseFactory> 
   ().ImplementedBy<DatabaseFactory>().LifestylePerWebRequest());
        container.Register(Component.For<IUnitOfWork> 
   ().ImplementedBy<UnitOfWork>().LifestylePerWebRequest());
        container.Register(Component.For<IRepositoryFactory<Legends, int>> 
    ().ImplementedBy<RepositoryFactory<Legends, int>> 
    ().LifestylePerWebRequest());
        container.Register(Component.For<IDiObjectMapper> 
    ().ImplementedBy<DiObjectMapper>().LifestylePerWebRequest());
        container.Register(Component.For<IDisposable> 
    ().ImplementedBy<Disposable>().LifestylePerWebRequest());
        container.Register(Component.For<IRepository<Legends, int>> 
     ().ImplementedBy<IRepositoryFactory<Legends, int>> 
     ().LifestylePerWebRequest());
container.Register(Component.For
().ImplementedBy().LifestylePerWebRequest());
容器.寄存器(组件.For)
()实施人
().LifestylePerWebRequest());
容器.寄存器(组件.For)
().ImplementedBy().LifestylePerWebRequest());
容器.寄存器(组件.For)
().ImplementedBy().LifestylePerWebRequest());
容器.寄存器(组件.For)
().ImplementedBy().LifestylePerWebRequest());
容器.寄存器(组件.For)
()实施人
().LifestylePerWebRequest());
容器.寄存器(组件.For)
().ImplementedBy().LifestylePerWebRequest());
容器.寄存器(组件.For)
().ImplementedBy().LifestylePerWebRequest());
容器.寄存器(组件.For)
()实施人
().LifestylePerWebRequest());

注意:我没有提到Repository和IRepository,它们实际上只包含相同的通用CRUD操作

这解决了我的问题:

         container.Register(Component
           .For(typeof(IRepositoryFactory<,>))
           .ImplementedBy(typeof(RepositoryFactory<,>))
           .LifestylePerWebRequest());
         container.Register(Component
           .For(typeof(IRepository<,>))
           .ImplementedBy(typeof(Repository<,>))
           .LifestylePerWebRequest());
container.Register(组件
.For(类型(IRepositoryFactory))
.实施人(类型(存储工厂))
.LifestylePerWebRequest());
容器寄存器(组件
.For(类型(i假定))
.ImplementedBy(类型(存储库))
.LifestylePerWebRequest());
   container.Register(Component.For<IDisposable> 
    ().ImplementedBy<IDatabaseFactory>().LifestylePerWebRequest());
     container.Register(Component.For<IRepository<Legends, int>> 
   ().ImplementedBy<Repository<Legends, int>> 
   ().LifestylePerWebRequest());
    container.Register(Component.For<ILegendsService> 
   ().ImplementedBy<LegendsService>().LifestylePerWebRequest());
        container.Register(Component.For<IDatabaseFactory> 
   ().ImplementedBy<DatabaseFactory>().LifestylePerWebRequest());
        container.Register(Component.For<IUnitOfWork> 
   ().ImplementedBy<UnitOfWork>().LifestylePerWebRequest());
        container.Register(Component.For<IRepositoryFactory<Legends, int>> 
    ().ImplementedBy<RepositoryFactory<Legends, int>> 
    ().LifestylePerWebRequest());
        container.Register(Component.For<IDiObjectMapper> 
    ().ImplementedBy<DiObjectMapper>().LifestylePerWebRequest());
        container.Register(Component.For<IDisposable> 
    ().ImplementedBy<Disposable>().LifestylePerWebRequest());
        container.Register(Component.For<IRepository<Legends, int>> 
     ().ImplementedBy<IRepositoryFactory<Legends, int>> 
     ().LifestylePerWebRequest());
         container.Register(Component
           .For(typeof(IRepositoryFactory<,>))
           .ImplementedBy(typeof(RepositoryFactory<,>))
           .LifestylePerWebRequest());
         container.Register(Component
           .For(typeof(IRepository<,>))
           .ImplementedBy(typeof(Repository<,>))
           .LifestylePerWebRequest());