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
2 Answers
Reset to default 0That '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
版权声明:本文标题:.net - Main solution url cannot hit my other solutions controller - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741207636a2358466.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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 uselocalhost:7127
to get get data fromlocalhost: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:05https://localhost:7127/api/member
andhttps://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<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