英文:
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<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;
}
}
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<AbpAspNetCoreMvcOptions>(options =>
{
options.ConventionalControllers
.Create(typeof(MyProjectApplicationModule).Assembly, opts =>
{
opts.RootPath = ""; //by default it's 'app'
});
});
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论