我正在尝试为我的ThirdParty
程序集中的服务创建Dynamic Web Api Controlers,以及为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
完全相同的模式。唯一的区别是EggAppService
与TaskAppService
如何为其他程序集中的服务创建动态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());
}
}
}
答案 0 :(得分:1)
您需要明确告诉ABP框架SimpleTaskSystemWebApiModule
取决于ThirdPartyApplicationModule
。
更改此行:
[DependsOn(typeof(AbpWebApiModule))] //We declare depended modules explicitly
到此:
[DependsOn(typeof(AbpWebApiModule), typeof(ThirdPartyApplicationModule))] //We declare depended modules explicitly
应该做的伎俩