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

[API Proposal]: Can DispatchProxy support "Create<TProxy>(Type interfaceType) where TProxy : DispatchProxy"? #65761

Closed
Mutuduxf opened this issue Feb 23, 2022 · 3 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Reflection untriaged New issue has not been triaged by the area owner

Comments

@Mutuduxf
Copy link

Mutuduxf commented Feb 23, 2022

Background and motivation

Our microservice framework is based on asp.net core and we have added the services as controllers into it. For the purposes of rpc operations we are using the interfaces as the rpc contracts between the microservices. The framework will register the interfaces into the ioc when the microservice is started. At this moment we can get the type of the interfaces. But the DispatchProxy support generic Create API only so we can only to reflect it and invoke the Create method.

API Proposal

namespace System.Reflection
{
    public abstract class DispatchProxy
    {
        public static object Create<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TProxy>(Type interfactType) where TProxy : DispatchProxy
        {
            return DispatchProxyGenerator.CreateProxyInstance(typeof(TProxy), interfactType);
        }
    }
}

API Usage

var proxy = DispatchProxy.Create<CustomProxy>(interfaceType);

Alternative Designs

No response

Risks

No response

@Mutuduxf Mutuduxf added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Feb 23, 2022
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Reflection untriaged New issue has not been triaged by the area owner labels Feb 23, 2022
@ghost
Copy link

ghost commented Feb 23, 2022

Tagging subscribers to this area: @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and motivation

Our microservice framework is based on asp.net core and we have added the services as controllers into it. For the purposes of rpc operations we are using the interfaces as the rpc contracts between the microservices. The framework will register the interfaces into the ioc when the microservice is started. At this moment we can get the type of the interfaces. But the DispatchProxy support generic Create API only so we can only to reflect it and invoke the Create method.

API Proposal

namespace System.Reflection
{
    public static object Create<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] TProxy>(Type interfactType)
            where TProxy : DispatchProxy
        {
            return DispatchProxyGenerator.CreateProxyInstance(typeof(TProxy), interfactType);
        }
}

API Usage

var proxy = DispatchProxy.Create<CustomProxy>(interfaceType);

Alternative Designs

No response

Risks

No response

Author: Mutuduxf
Assignees: -
Labels:

api-suggestion, area-System.Reflection, untriaged

Milestone: -

@MichalStrehovsky
Copy link
Member

Previous discussion of a similar proposal: #28419.

@buyaa-n
Copy link
Contributor

buyaa-n commented Mar 1, 2022

The API proposal looks useful to me, though as per the discussion in #28419 because of reliable AOT support and becuase there is a reflection based work around for this we don't want to add this overload, closing

@buyaa-n buyaa-n closed this as completed Mar 1, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Apr 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Reflection untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

3 participants