✅ Working with repository in ASP.NET
I'm trying to use an orderRepository. But when i use it i get the message in my index.cshtml file: System.NullReferenceException: 'Object reference not set to an instance of an object.'
9 Replies
Now in my OrderController i have a method Index that looks like this:
the orders variable that is in comment works. But my repo not. The All method looks like follows:
so basically when i use this code in my Index: everything works
but i want to use the repo
it seems you are missing registering that dependency.
dependency injection registrations are typically done inside Program.cs by services.AddSingleton, or AddTransient or AddScoped
yeah yeah i think i found something
but i reagisterd it
but i think the issue is
in my OrderController i do it like this:
so i'm calling the GenericRepository instead of the Orderrepository
yeah i found it
if i use this code in my OrderController is works:
nice, congrats!