✅ "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.
20 Replies
Show
CustomerController
and show where you're registering your implementation of
ICustomerRepository
in DI, because the error is saying you don't have oneAight, this seems... fine
How do you register the repository?
This is your interface class, yes
How do you register it?
Sorry for late replies my brain is giving 404 rn
So am I to assume you don't register it anywhere, because you didn't know you have to?
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
Dependency injection in ASP.NET Core
Learn how ASP.NET Core implements dependency injection and how to use it.
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
it looks like at some point you followed directions for a different version of ASP.NET
There, that's it, that's the registration bit
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
Yep I looked at online where I stuck with it
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@Jimmacle in that case it gave me an error on CustomerController
well that's further than you were before
you should double check your controller's constructor