admin管理员组

文章数量:1279017

I have 3 different solutions running (main, letter and member), but everything needs to be accessible by the main projects url, the letter one works when I am running the project from the main url port but for some reason my member one doesn't work, it only works on the port number it is running on.

My main url is localhost:7127 and it works for hitting my letter controller even tho it starts on a different port, but for my member it only hits on it's own url https://localhost:7207

I have tried changing the Program files to allow from multiple different hosts but it just doesn't want to work, here is what I tried and was the difference between my letter and member but no prevail, is this even a Pam.cs issue or am I going down the wrong rabbit hole ?

Main

builder.Services.AddCors(options =>
{
    options.AddPolicy("AllowAll", policy =>
    {
        policy.AllowAnyOrigin()
              .AllowAnyMethod()
              .AllowAnyHeader();
    });
});

Here are my postman calls as well

https://localhost:7127/api/member is a get call and is giving me a 500 error

Unable to resolve service for type 'Member.Services.FormService' while attempting to activate 'Member.API.Controllers.MemberFormController'.

but when I ran this https://localhost:7207/api/member then it works, so I need it to run on that 7127 port and I cannot figure out why it is not running there

I have 3 different solutions running (main, letter and member), but everything needs to be accessible by the main projects url, the letter one works when I am running the project from the main url port but for some reason my member one doesn't work, it only works on the port number it is running on.

My main url is localhost:7127 and it works for hitting my letter controller even tho it starts on a different port, but for my member it only hits on it's own url https://localhost:7207

I have tried changing the Program files to allow from multiple different hosts but it just doesn't want to work, here is what I tried and was the difference between my letter and member but no prevail, is this even a Pam.cs issue or am I going down the wrong rabbit hole ?

Main

builder.Services.AddCors(options =>
{
    options.AddPolicy("AllowAll", policy =>
    {
        policy.AllowAnyOrigin()
              .AllowAnyMethod()
              .AllowAnyHeader();
    });
});

Here are my postman calls as well

https://localhost:7127/api/member is a get call and is giving me a 500 error

Unable to resolve service for type 'Member.Services.FormService' while attempting to activate 'Member.API.Controllers.MemberFormController'.

but when I ran this https://localhost:7207/api/member then it works, so I need it to run on that 7127 port and I cannot figure out why it is not running there

Share Improve this question edited Feb 26 at 6:58 Tiny Wang 16.1k2 gold badges18 silver badges38 bronze badges asked Feb 25 at 11:06 ApolloKS09ApolloKS09 236 bronze badges 4
  • May I know how to reproduce your issue? Per my understanding, we usually host one app on one port, so that if we run the Member solution on port 7207 we should not be able to call the API in Member solution on port 7127, unless we run the Member solution on 7127 too. Since the Main project already runs in 7127, so that you might host the Member solution as a child web app like IIS Virtual Directory. But you didn't mention that. Could you please explain more about your issue? – Tiny Wang Commented Feb 26 at 7:12
  • My main url is localhost:7127 and it works fxxx tho it starts on a different port -> we can know the Letter solution can be accessed by 2 different ports, which looks like your Main solution contains a proxy for the Letter solution, so that you can use localhost:7127 to get get data from localhost:another_port. Or you might add project refernce in the Main solution, so that you can inject service in Letter solution into Main solution so that you can access Letter API from Main port, and you might run Letter solution seperately so that you have 2 ports for the same solution. – Tiny Wang Commented Feb 26 at 9:05
  • If so, you shall do the same thing in your Member solution. Let's see the error message, just like what @oscar said in his post, it indicates that the Member project’s services (like Member.Services.FormService) aren’t registered in the Main project’s DI container. In the meantime, you can use postman to call both https://localhost:7127/api/member and https://localhost:7207/api/member so that I assume you host Member solution in 2 different posts at the same time too. – Tiny Wang Commented Feb 26 at 9:05
  • Then to resolve the issue and make the Main solution to call Member API successfully, we need to firstly make sure the project refernece is added successfully, we can check whether we have <ProjectReference Include="..\path_to_member_project\member.csproj" />, then take a look at the configuration in Main project about service injection, I'm afraid what Letter solution has in Main solution, the Member solution should have the same configufation. – Tiny Wang Commented Feb 26 at 9:06
Add a comment  | 

2 Answers 2

Reset to default 0

That 'Unable to resolve service' error indicates that your main project is trying to build your MemberFormController but doesn't have the necessary dependency (FormService) registered in it's DI container.

Try adding the service in the startup for your main project. I'm assuming your main project references the letter and member projects.

public void ConfigureServices(IServiceCollection services)
{
    services
        .AddScoped<IFormService, FormService>();
}

If there's any more dependencies, or if FormService has any further dependencies, they will need adding as well.

  • Unable to resolve service for type 'Member.Services.FormService' is due to dependency not resolved for MemberFormController.
  • You have to register your interface and service class to resolve it

For example, if the interface name is IFormService and the class file name is FormService then you can register by using below code.

services.AddScoped<IFormService, FormService>();

本文标签: netMain solution url cannot hit my other solutions controllerStack Overflow