1

我正在尝试为我的程序集中的服务创建动态 Web Api 控制器ThirdParty,以及为我的程序集中的服务创建控制器SimpleTaskSystem,其中包含以下内容:

[DependsOn(typeof(AbpWebApiModule))] //We declare depended modules explicitly
public class SimpleTaskSystemWebApiModule : AbpModule
{
    public override void Initialize()
    {
        IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

        IocManager.RegisterAssemblyByConvention(Assembly.GetAssembly(typeof(ThirdPartyApplicationModule)));

        DynamicApiControllerBuilder
            .For<ITaskAppService>("tasksystem/task")
            .Build();

        // this works when I call
        // /api/services/eggsystem/egg/GetEggs
        DynamicApiControllerBuilder 
            .For<IEggAppService>("eggsystem/egg")
            .ForMethod("GetEggs").WithVerb(HttpVerb.Get)
            .Build();

        // When doesn't work when I try to call
        // /api/services/fleasystem/flea/GetFleas
        DynamicApiControllerBuilder
          .For<IFleaAppService>("fleasystem/flea")
          .ForMethod("GetFleas").WithVerb(HttpVerb.Get)
          .Build();
    }
}

当我尝试调用时出现以下错误

/api/services/fleasystem/flea/GetFleas

Castle.MicroKernel.Handlers.HandlerException 发生消息:Castle.Windsor.dll 中出现“Castle.MicroKernel.Handlers.HandlerException”类型的第一次机会异常附加信息:无法将组件“ThirdParty.Application.Fleas.FleaAppService”创建为它具有要满足的依赖关系。

'ThirdParty.Application.Fleas.FleaAppService' 正在等待以下依赖项:

  • 未注册的服务“ThirdParty.Core.Fleas.IFleaRepository”。

  • 服务 'Abp.Domain.Repositories.IRepository`1[[ThirdParty.Core.Dogs.Dog, ThirdParty.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' 未注册。

两者FleaAppService(以及所有与 . 相关的类Flea)都遵循与EggAppService. 唯一的区别在于EggAppServiceTaskAppService

我需要做什么才能为其他程序集中的服务创建动态 Web api 控制器?

更新

作为记录,据我所知,我正在注册缺少的依赖项。我ThirdPartyApplicationModule的定义为

namespace ThirdParty.Application
{
    /// <summary>
    /// 'Application layer module' for this project.
    /// </summary>
    [DependsOn(typeof(ThirdPartyCoreModule), typeof(AbpAutoMapperModule))]
    public class ThirdPartyApplicationModule : AbpModule
    {
        public override void Initialize()
        {
            //This code is used to register classes to dependency injection system for this assembly using conventions.
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());

            //We must declare mappings to be able to use AutoMapper
            DtoMappings.Map();
        }
    }
}

ThirdPartyCoreModule定义为

namespace ThirdParty.Core
{
    /// <summary>
    /// 'Core module' for this project.
    /// </summary>
    public class ThirdPartyCoreModule : AbpModule
    {
        public override void Initialize()
        {
            //This code is used to register classes to dependency injection system for this assembly using conventions.
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
        }
    }
}
4

1 回答 1

2

您需要明确告诉 ABP 框架SimpleTaskSystemWebApiModule依赖于ThirdPartyApplicationModule.

更改此行:

[DependsOn(typeof(AbpWebApiModule))] //We declare depended modules explicitly

对此:

[DependsOn(typeof(AbpWebApiModule), typeof(ThirdPartyApplicationModule))] //We declare depended modules explicitly

应该做的伎俩

于 2015-12-08T07:13:00.177 回答