C
C#4mo 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
Angius4mo ago
Show CustomerController
Jimmacle
Jimmacle4mo ago
and show where you're registering your implementation of ICustomerRepository in DI, because the error is saying you don't have one
RXPHXEL
RXPHXEL4mo ago
No description
Angius
Angius4mo ago
Aight, this seems... fine How do you register the repository?
RXPHXEL
RXPHXEL4mo ago
No description
Angius
Angius4mo ago
This is your interface class, yes How do you register it?
RXPHXEL
RXPHXEL4mo ago
No description
RXPHXEL
RXPHXEL4mo ago
Sorry for late replies my brain is giving 404 rn
Angius
Angius4mo ago
So am I to assume you don't register it anywhere, because you didn't know you have to?
RXPHXEL
RXPHXEL4mo ago
No description
No description
Jimmacle
Jimmacle4mo 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
RXPHXEL4mo 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
Jimmacle4mo ago
it looks like at some point you followed directions for a different version of ASP.NET
Angius
Angius4mo ago
There, that's it, that's the registration bit
Jimmacle
Jimmacle4mo 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
RXPHXEL4mo ago
Yep I looked at online where I stuck with it
Jimmacle
Jimmacle4mo 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
RXPHXEL4mo ago
@Jimmacle in that case it gave me an error on CustomerController
No description
Jimmacle
Jimmacle4mo 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