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

Add C# and JavaScript Static Client Proxy Generation #9905

Merged
merged 36 commits into from Sep 15, 2021

Conversation

realLiangshiwei
Copy link
Member

@realLiangshiwei realLiangshiwei commented Aug 26, 2021

Resolve #9864

Usage:

abp generate-proxy -t ng

abp generate-proxy -t js -m identity -u https://localhost:44305

image

abp generate-proxy -t csharp -m identity -u https://localhost:44305

  • *.partial.cs is a partial class of client proxy class, it uses to add custom methods.
  • *.generate-proxy.json is the API definition of the module, should not change it.

image

    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(IIdentityRoleAppService))]
    public partial class IdentityRoleClientProxy : ClientProxyBase<IIdentityRoleAppService>, IIdentityRoleAppService
    {
        public virtual async Task<ListResultDto<IdentityRoleDto>> GetAllListAsync()
        {
            return await RequestAsync<ListResultDto<IdentityRoleDto>>(nameof(GetAllListAsync));
        }
        // .......
 
        public virtual async Task DeleteAsync(Guid id)
        {
            await RequestAsync(nameof(DeleteAsync), id);
        }
 
    }

@realLiangshiwei realLiangshiwei marked this pull request as draft August 26, 2021 17:32
@realLiangshiwei realLiangshiwei added this to the 5.0-preview milestone Aug 26, 2021
@hikalkan
Copy link
Member

hikalkan commented Sep 1, 2021

Hi,

I tried but failed with the following exception:

Could not get DynamicHttpClientProxyConfig for Volo.Abp.Identity.IIdentityRoleAppService.
Volo.Abp.AbpException: Could not get DynamicHttpClientProxyConfig for Volo.Abp.Identity.IIdentityRoleAppService.
   at Volo.Abp.Http.Client.HttpProxyExecuter.MakeRequestAsync(HttpProxyExecuterContext context) in D:\Github\abp\framework\src\Volo.Abp.Http.Client\Volo\Abp\Http\Client\HttpProxyExe
cuter.cs:line 92
   at Volo.Abp.Http.Client.HttpProxyExecuter.MakeRequestAndGetResultAsync[T](HttpProxyExecuterContext context) in D:\Github\abp\framework\src\Volo.Abp.Http.Client\Volo\Abp\Http\Clie
nt\HttpProxyExecuter.cs:line 60
   at Volo.Abp.Http.Client.ClientProxying.ClientProxyBase`1.RequestAsync[T](String methodName, Object[] arguments) in D:\Github\abp\framework\src\Volo.Abp.Http.Client\Volo\Abp\Http\
Client\ClientProxying\ClientProxyBase.cs:line 24
   at Volo.Abp.Identity.HttpApi.Client.ClientProxies.IdentityRoleClientProxy.GetListAsync(GetIdentityRolesInput input) in D:\Github\abp\modules\identity\src\Volo.Abp.Identity.HttpAp
i.Client\ClientProxies\IdentityRoleClientProxy.cs:line 25

I did my test in a branch: https://github.com/abpframework/abp/tree/services-proxy-trying
See me commit: 6f87944

I am trying to use static c# proxies for the identity module. Actually, we will do this for all modules as a part of this PR. Can you please make it working?

I also have some findings and suggestions;

  • We can set namespace from the api-definition json and add ClientProxies to it. Example:
    For Volo.Abp.Identity.IdentityRoleController we can create IdentityRoleClientProxy in the Volo.Abp.Identity.ClientProxies namespace.
  • Add // ReSharper disable once CheckNamespace on top of the class, so we Rider developers don't get warning :)
    • identity-generate-proxy.json is not embedded resource by default. abp generate-proxy should make it embedded and also we should add it to virtual file system. How can we automate that? Adding to VFS may be manual, but embedded resource can be easily automated by manipulating the csproj file.
  • I sugges to rename IdentityRoleClientProxy.partial.cs to IdentityRoleClientProxy.Generated.cs, move the generated code here and leave the IdentityRoleClientProxy.cs as empty for the developer.
  • [ExposeServices(typeof(IIdentityRoleAppService))] should be [ExposeServices(typeof(IIdentityRoleAppService), typeof(IdentityRoleClientProxy))], so we can also inject by class.

@hikalkan
Copy link
Member

hikalkan commented Sep 2, 2021

JavaScript proxies perfectly works, great. I tried it for identity's user page: 5a0217b

We should make this for all modules. I mean we will use static JS proxies for the modules, from now.

@hikalkan
Copy link
Member

Currently, IdentityUserClientProxy.cs is like that:

[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IIdentityUserAppService), typeof(IdentityUserClientProxy))]
public partial class IdentityUserClientProxy : ClientProxyBase<IIdentityUserAppService>, IIdentityUserAppService
{
}

and IdentityUserClientProxy.Generated.cs is like that:

public partial class IdentityUserClientProxy
{
    ....
}

It would be better if we move attributes (Dependency and ExposeServices) and inheritance/implementation to the generated file, so use do not accidently deletes them.

@hikalkan
Copy link
Member

I am merging this. You can address my comment (#9905 (comment)) as a separate PR.

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

Successfully merging this pull request may close these issues.

C# and JavaScript Static Client Proxy Generation
3 participants