我想在我的SimpleTaskSystem
組件來創建服務我ThirdParty
大會服務動態網頁API Controlers,以及控制器,具有如下:如何爲不同程序集中的服務創建動態Web API控制器?
[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' 這是未註冊。
Service'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());
}
}
}
您需要註冊缺少的依賴,因爲有消息稱。 –
如何註冊這些依賴關係? – DaveDev
https://github.com/castleproject/Windsor/blob/master/docs/installers.md –