Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override base path for service api #3082

Closed
dolphinsd opened this issue Feb 14, 2018 · 5 comments
Closed

Override base path for service api #3082

dolphinsd opened this issue Feb 14, 2018 · 5 comments

Comments

@dolphinsd
Copy link

@dolphinsd dolphinsd commented Feb 14, 2018

  1. What about base path, like /api/services/, I want to change '' - empty string so just /api/
  2. What about custom mapping path, for example I want to remap all reference to OgranizationUnits controllers, simply to Groups, can I configure it?

Looks like a simple configuration enhancement?

Can I override AbpWebApiModule and PostInitialize?

@acjh

This comment has been minimized.

Copy link
Contributor

@acjh acjh commented Mar 28, 2018

This is hardly an enhancement. Don't say something is simple if you don't know how to solve it.
It's already possible to some extent, and does not seem a worthwhile change to the framework.

  1. Add the following in MyProjectWebCoreModule:

    Configuration.Modules.AbpAspNetCore()
        .CreateControllersForAppServices(
            typeof(MyProjectApplicationModule).GetAssembly()
        )
        // Add this:
        .ConfigureControllerModel(model =>
        {
            foreach (var action in model.Actions)
            {
                var verb = ProxyScriptingHelper.GetConventionalVerbForMethodName(action.ActionName);
                var constraint = new HttpMethodActionConstraint(new List<string> { verb });
    
                foreach (var selector in action.Selectors)
                {
                    selector.ActionConstraints.Add(constraint);
                    selector.AttributeRouteModel = new AttributeRouteModel(
                        new RouteAttribute(
                            $"api/{action.Controller.ControllerName}/{action.ActionName}"
                        )
                    );
                }
            }
        });

    Clearly, this would break JavaScript references to services provided in the template (e.g. abp.services.app.user), but you can check that it works in Swagger and the direct link.

  2. Rename OrganizationUnitAppService to:

    public class GroupsAppService : MyProjectAppServiceBase, IOrganizationUnitAppService

    Then register it:

    IocManager.Register<IOrganizationUnitAppService, GroupsAppService>();
@dolphinsd

This comment has been minimized.

Copy link
Author

@dolphinsd dolphinsd commented Mar 30, 2018

Your approach is not practical as you have to do that to many, many classes.

@acjh

This comment has been minimized.

Copy link
Contributor

@acjh acjh commented Mar 30, 2018

Do what to many classes?

@dolphinsd

This comment has been minimized.

Copy link
Author

@dolphinsd dolphinsd commented Mar 30, 2018

Your solution requires laborious workout around for APB class as a service.

For my own services I can map routes with one line:
[Route("myroute/[controller]/[action]")]
in front AppService definition

One gotcha - methods needs to be defined for each function.

What I am asking is a fix for the framework issue.

@acjh

This comment has been minimized.

Copy link
Contributor

@acjh acjh commented Mar 31, 2018

It's a one-time configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.