1

My project has an interface that takes two generic inputs and is used by multiple classes. Each of these classes inherits the interface with different concrete classes

public interface IEndpointManager<TRequest, TResponse>
{
    Task<TResponse?> CreateRequestAsync(TRequest request);
}

This is one of the classes that inherits the interface.

public class PatientFinderPlusEndpoint : IEndpointManager<RequestModel<PatientFinderRequestModel>, PatientFinderResponseModel>

And then the controller, where I am injecting the service

public NewPcfPlusController([FromKeyedServices("Pcf+EndpointManager")] IEndpointManager<RequestModel<PatientFinderRequestModel>, 
            PatientFinderResponseModel> endpointManager)

The problem is in Startup.cs, trying to register the keyed service.

services.AddKeyedSingleton<IEndpointManager<RequestModel<PatientFinderRequestModel>, PatientFinderResponseModel>, PatientFinderPlusEndpoint>("Pcf+EndpointManager");

It errs on the parameter PatientFinderPlusEndpoint with this error

The type 'TC.Enterprise.eServicesOrchestrator.NewPath.Service.Endpoints.PatientFinderPlusEndpoint' must be convertible to 'TC.Enterprise.eServicesOrchestrator.NewPath.Service.Endpoints.IEndpointManager<TC.Enterprise.eServicesOrchestrator.NewPath.Service.Public.RequestModel<TC.Enterprise.eServicesOrchestrator.NewPath.Service.Public.Models.PatientFinder.PatientFinderRequestModel>,TC.Enterprise.eServicesOrchestrator.NewPath.Service.Public.Models.PatientFinder.PatientFinderResponseModel>' in order to use it as parameter

I'm certain its the type parameters in the interface. If I removed them then the error goes away. I thought since the class inherits the interface it would be seen as "having" the same type parameters.

1
  • 2
    can't reproduce. Double check usings/classes with same names Commented May 30 at 21:27

1 Answer 1

2

double-check namespaces and assembly references. If you're using RequestModel<PatientFinderRequestModel> in multiple places (like public/internal models), there may be more than one type named RequestModel<PatientFinderRequestModel> — even if they look identical.

Sign up to request clarification or add additional context in comments.

1 Comment

Minhazul, You are correct. There is a PatientFinderPlusEndpoint class is in a dependent project and my project was referencing that namespace. Once I changed the namespace to my project it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.