使用Abp框架 – 为什么我的端点命名会变得扭曲?

huangapple go评论66阅读模式
英文:

Using Abp framework - Why does my endpoint naming gets distorted?

问题

public class LessonAppService : ApplicationService,
ILessonService // 实现了 IBookAppService 接口
{
private readonly IRepository<Lesson, Guid> _lessonRepository;

public LessonAppService(IRepository<Lesson, Guid> lessonRepository)
{
    _lessonRepository = lessonRepository;
}

public async Task CreateLessonAsync(CreateLessonDTO input)
{
    try
    {
        var lesson = ObjectMapper.Map<CreateLessonDTO, Lesson>(input);
        await _lessonRepository.InsertAsync(lesson);
    }
    catch (Exception ex)
    {
        throw;
    }
}

}

从这个代码创建的 API 路由是:
/api/app/lesson/lesson

而其他所有端点看起来像这样:
/api/account/login

有关原因和如何修复的任何想法吗?

英文:

Hello i got a very simple service that looks like this:

 public class LessonAppService :ApplicationService,
    ILessonService //implement the IBookAppService
    {
        private readonly IRepository&lt;Lesson, Guid&gt; _lessonRepository;

        public LessonAppService(IRepository&lt;Lesson, Guid&gt; lessonRepository)
        {
            _lessonRepository = lessonRepository;
        }

        public async Task CreateLessonAsync(CreateLessonDTO input)
        {
            try
            {
                var lesson = ObjectMapper.Map&lt;CreateLessonDTO, Lesson&gt;(input);
                await _lessonRepository.InsertAsync(lesson);
            }
            catch (Exception ex)
            {

                throw;
            }

        }

The api route thats created from this is :
/api/app/lesson/lesson

While all the other endpoints look like this:
/api/account/login

Any idea on why? and how to fix it?

答案1

得分: 0

ABP Framework将路由路径设置为app,以区分模块端点和您自己的端点。您可以通过配置AbpAspNetCoreMvcOptions随时删除路由路径或进行更改。

打开您的web/host模块类,并按照以下方式配置AbpAspNetCoreMvcOptions选项以设置新的路由路径

Configure<AbpAspNetCoreMvcOptions>(options =>
{
    options.ConventionalControllers
        .Create(typeof(MyProjectApplicationModule).Assembly, opts =>
            {
                opts.RootPath = ""; //默认为'app'
            });
});

然后您的路由约定将被更改。有关更多信息,请参阅此文档:https://docs.abp.io/en/abp/latest/API/Auto-API-Controllers#route

英文:

ABP Framework sets route path as app to distinguish the module endpoints with your own endpoints. You can remove the route path or change whenever you want by configuring the AbpAspNetCoreMvcOptions.

Open your web/host module class and configure the AbpAspNetCoreMvcOptions options as below to set a new route path:

Configure&lt;AbpAspNetCoreMvcOptions&gt;(options =&gt;
{
    options.ConventionalControllers
        .Create(typeof(MyProjectApplicationModule).Assembly, opts =&gt;
            {
                opts.RootPath = &quot;&quot;; //by default it&#39;s &#39;app&#39;
            });
});

Then your route convention will be changed. For more info see this documentation: https://docs.abp.io/en/abp/latest/API/Auto-API-Controllers#route

huangapple
  • 本文由 发表于 2023年3月9日 18:11:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75683141.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定