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 Helper builder extension to use custom MethodProviders #91

Open
CSharpStudio opened this issue Oct 22, 2020 · 2 comments
Open

Add Helper builder extension to use custom MethodProviders #91

CSharpStudio opened this issue Oct 22, 2020 · 2 comments
Assignees

Comments

@CSharpStudio
Copy link

I want to dynamic add methods to RpcRouteMetaData,but StaticRpcMethodDataAccessor is internal and I have to implemant IRpcMethodProvider myself. The problem is the RpcEndpointBuilder cannot be extented, and if I add a new UseJsonRpc method with MyRpcEndpointBuilder, I have to create another RpcHttpRouter because it is internal also.

@Gekctek
Copy link
Collaborator

Gekctek commented Nov 3, 2020

This should be able to be done, just not with using any of the built in extension methods. Youll need to register a new IRpcMethodProvider in the servicecollection before calling AddJsonRpc(). Then if you call

var router = new RpcHttpRouter();
app.UseRouter(router);

for applicationbuilder, it should work for you. Try it out. if it doesnt work then i can fix it and/or add a helper method to the BuilderExtensions

@CSharpStudio
Copy link
Author

CSharpStudio commented Nov 12, 2020

This should be able to be done, just not with using any of the built in extension methods. Youll need to register a new IRpcMethodProvider in the servicecollection before calling AddJsonRpc(). Then if you call

var router = new RpcHttpRouter();
app.UseRouter(router);

for applicationbuilder, it should work for you. Try it out. if it doesnt work then i can fix it and/or add a helper method to the BuilderExtensions

Thanks, I fix it out with a RpcEndpointContainer like RpcEndpointBuilder and use a new UserJsonRpcRouter replace the UserJsonRpc method.
If the internal RpcRouteMetaData Resolve() changed to protected, it will be extended easier.

public static IApplicationBuilder UseJsonRpcRouter(this IApplicationBuilder app, Action<RpcEndpointContainer> configure = null)
{
     var container = app.ApplicationServices.GetService<RpcEndpointContainer>();
     if (container == null)
          throw new InvalidOperationException("AddJsonRpcRouter() needs to be called in the ConfigureServices method.");
     configure?.Invoke(container);
     return app.UseJsonRpc(options => { }); // the options of RpcEndpointBuilder is no use here
}

@Gekctek Gekctek self-assigned this Nov 14, 2020
@Gekctek Gekctek changed the title can RpcEndpointBuilder change method Resolve to internal protected? Add Helper builder extension to use custom MethodProviders Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants