1

I'm trying to create Dynamic Web Api Controlers for services in my ThirdParty assembly, as well as controllers for the services in my SimpleTaskSystem assembly, with the following:

[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();
    }
}

I'm getting the following error when I try to call

/api/services/fleasystem/flea/GetFleas

Castle.MicroKernel.Handlers.HandlerException occurred Message: A first chance exception of type 'Castle.MicroKernel.Handlers.HandlerException' occurred in Castle.Windsor.dll Additional information: Can't create component 'ThirdParty.Application.Fleas.FleaAppService' as it has dependencies to be satisfied.

'ThirdParty.Application.Fleas.FleaAppService' is waiting for the following dependencies:

  • Service 'ThirdParty.Core.Fleas.IFleaRepository' which was not registered.

  • Service 'Abp.Domain.Repositories.IRepository`1[[ThirdParty.Core.Dogs.Dog, ThirdParty.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.

Both FleaAppService (and all related classes to Flea) follow the exact same pattern as the EggAppService. The only difference is EggAppService exists in the same assembly as the TaskAppService

What do I need to do to create a dynamic web api controllers to services in other assemblies?

Update

For the record, as far as I can see I'm registering the missing dependencies. My ThirdPartyApplicationModule is defined as

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();
        }
    }
}

and ThirdPartyCoreModule is defined as

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
  • 41,155
  • 72
  • 223
  • 385

1 Answers1

2

You need to tell the ABP Framework explicitly that the SimpleTaskSystemWebApiModule depends on the ThirdPartyApplicationModule.

Changing this line:

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

to this:

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

should do the trick

Jacques Snyman
  • 4,115
  • 1
  • 29
  • 49