I have created a asp.net web api while running api I am getting this error
System.InvalidOperationException: Unable to resolve service for type 'movieRentalApp.Data.DataContext' while attempting to activate 'movieRentalpp.Controllers.CustomersController'.
this is C# code for Customer class
namespace movieRentalApp.Model { public class Customer { public int Id { get; set; } public string? CustomerName { get; set; } public string? Email { get; set; } public DateTime DOB { get; set; } public int Phone { get; set; } } }
this is code for controller namespace movieRentalApp.Model { public class Customer { public int Id { get; set; } public string? CustomerName { get; set; } public string? Email { get; set; } public DateTime DOB { get; set; } public int Phone { get; set; } } } this is db context
using Microsoft.EntityFrameworkCore; using movieRentalApp.Model;
namespace movieRentalApp.Data { public class DataContext : DbContext { public DataContext(DbContextOptions options) : base(options) {
}
public DbSet<Customer> Customers { get; set; }
public DbSet<Personnel> Personnels { get; set; }
public DbSet<Rental> Rentals { get; set; }
//protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseSqlServer(" Data Source=localhost\\SQLEXPRESS;Initial Catalog=MovieRentalAppDB;Integrated Security=True;Pooling=False;Encrypt=False;TrustServerCertificate=True, ");
}
}