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

Why is the module not using auto api controllers? #1731

Closed
wakuflair opened this issue Sep 9, 2019 · 9 comments
Closed

Why is the module not using auto api controllers? #1731

wakuflair opened this issue Sep 9, 2019 · 9 comments

Comments

@wakuflair
Copy link
Contributor

I noticed that auto api controllers are not used in the template of the module, but instead the controller class is defined (eg SampleController).

However, you also know that creating a controller for each application service is a tedious job, so I want to know why the auto api controller is not used in modules? Is this a violation of the best practice?

@maliming
Copy link
Member

maliming commented Sep 9, 2019

https://docs.abp.io/en/abp/latest/Best-Practices/Module-Architecture#http-layer

HTTP API package only depends on the Application.Contracts package. It does not depend on the Application package.

image

@wakuflair
Copy link
Contributor Author

wakuflair commented Sep 9, 2019

@maliming
Yes, I found out that the HttpApi project does not reference the Application project.
And I tried to use the auto api controller method without changing the dependencies by adding the following code in the XXXHttpApiModule ConfigureServices method:

            Configure<AbpAspNetCoreMvcOptions>(options =>
            {
                options
                    .ConventionalControllers
                    .Create(typeof(XXXApplicationContractsModule).Assembly);
            });

I used ApplicationContractsModule insteadof ApplicationModule, but this does not work.

So, is there a win-win approach that can use the auto api controller and follow the best practice?

@maliming maliming closed this as completed Sep 9, 2019
@wakuflair
Copy link
Contributor Author

Thanks to @maliming , I got it.

@felipemoreira2x
Copy link

@wakuflair Hi!

How did you solve this issue ?

@wakuflair
Copy link
Contributor Author

wakuflair commented Nov 1, 2019

Hi @felipemoreira2x
Just use the options.ConventionalControllers.Create in the ConfigureServices method of YourModuleWebUnifiedModule.cs:

        public override void ConfigureServices(ServiceConfigurationContext context)
        {
	    ... 

            // Auto controllers
            Configure<AbpAspNetCoreMvcOptions>(options =>
            {
                options.ConventionalControllers.Create(typeof(YourModuleApplicationModule).Assembly);
            });
        }

@hikalkan
Copy link
Member

hikalkan commented Nov 1, 2019

So, is there a win-win approach that can use the auto api controller and follow the best practice?

For the modules, we couldn't find a way of using auto api controllers without depending on the application service implementation, unfortunately.

@felipemoreira2x
Copy link

Hi @felipemoreira2x
Just use the options.ConventionalControllers.Create in the ConfigureServices method of YourModuleWebUnifiedModule.cs:

        public override void ConfigureServices(ServiceConfigurationContext context)
        {
	    ... 

            // Auto controllers
            Configure<AbpAspNetCoreMvcOptions>(options =>
            {
                options.ConventionalControllers.Create(typeof(PersonnelManagementApplicationModule).Assembly);
            });
        }

Thanks @wakuflair. It worked.

@jevonsflash
Copy link

It's not exactly a win-win situation ,it only works on single applications. In the gateway layer of the microservice, there is no way to get an interface definition, because it does not rely on ApplicationModuel and those Api for proxy cannot be automatically generated

Hi @felipemoreira2x
Just use the options.ConventionalControllers.Create in the ConfigureServices method of YourModuleWebUnifiedModule.cs:

        public override void ConfigureServices(ServiceConfigurationContext context)
        {
	    ... 

            // Auto controllers
            Configure<AbpAspNetCoreMvcOptions>(options =>
            {
                options.ConventionalControllers.Create(typeof(PersonnelManagementApplicationModule).Assembly);
            });
        }

Thanks @wakuflair. It worked.

@wakuflair
Copy link
Contributor Author

wakuflair commented Mar 23, 2023

Yes you are right.
It's like a hack to let you use auto controller in a module, don't do it in a real scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants