I am using asp.net core 2.2 version

Below is my appSettingsDevelopment.JSON

{ 
 "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=DatingApp.db"
  }
}

Below is my .csproj

    <Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.4" />
  </ItemGroup>

</Project>

Below is how I am accessing connectionstring

public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

 public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<DataContext>(x => 
         x.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
    }

I have seen and read all the related threads but somehow I am unable to fix this. I get below mentioned errors:

Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Microsoft.EntityFrameworkCore.DbContext]' while attempting to activate 'Dating.API.Data.DataContext'.

0 Answers