C
C#5mo ago
RXPHXEL

✅ "An unhandled exception occurred while processing the request."

Hi, I added linked code as well, the problem is whenever I start the build, it is giving me the error in the description. In my Views folder I have added a new folder called Customer and added two razor view start files, one is named List the other one is called Empty. I tried to google it but couldn't find a solution and couldn't find a documentation as well. Could you please help me? Thank you so much.
No description
No description
No description
No description
20 Replies
Angius
Angius5mo ago
Show CustomerController
Jimmacle
Jimmacle5mo ago
and show where you're registering your implementation of ICustomerRepository in DI, because the error is saying you don't have one
RXPHXEL
RXPHXELOP5mo ago
No description
Angius
Angius5mo ago
Aight, this seems... fine How do you register the repository?
RXPHXEL
RXPHXELOP5mo ago
No description
Angius
Angius5mo ago
This is your interface class, yes How do you register it?
RXPHXEL
RXPHXELOP5mo ago
No description
RXPHXEL
RXPHXELOP5mo ago
Sorry for late replies my brain is giving 404 rn
Angius
Angius5mo ago
So am I to assume you don't register it anywhere, because you didn't know you have to?
RXPHXEL
RXPHXELOP5mo ago
No description
No description
Jimmacle
Jimmacle5mo ago
you're sharing basically every file except the one that we need to see, which is your Program.cs or Startup.cs that's where you have to register services to be able to inject them into your controllers
RXPHXEL
RXPHXELOP5mo ago
Basically I only write void ConfigureServices(IServiceCollection services) { services.AddDbContext<LibraryDBContext>(options => options.UseInMemoryDatabase("LibraryManagement")); services.AddTransient<ICustomerRepository, CustomerRepository>(); services.AddTransient<IAuthorRepository, AuthorRepository>(); services.AddTransient<IBookRepository, BookRepository>(); services.AddMvc(); } part
No description
Jimmacle
Jimmacle5mo ago
it looks like at some point you followed directions for a different version of ASP.NET
Angius
Angius5mo ago
There, that's it, that's the registration bit
Jimmacle
Jimmacle5mo ago
you defined a ConfigureServices method that isn't standard for this type of template, and you never call it so none of that is actually getting registered
RXPHXEL
RXPHXELOP5mo ago
Yep I looked at online where I stuck with it
Jimmacle
Jimmacle5mo ago
you need to do all that stuff on builder.Services before calling builder.Build() where it says // Add services to the container add stuff like builder.Services.AddTransient<ICustomerRepository, CustomerRepository>(); also fwiw, repositories over EF core is not recommended
RXPHXEL
RXPHXELOP5mo ago
@Jimmacle in that case it gave me an error on CustomerController
No description
Jimmacle
Jimmacle5mo ago
well that's further than you were before you should double check your controller's constructor
Want results from more Discord servers?
Add your server