Why do I get this error:
Cannot convert lambda expression to type 'ServiceLifetime' because it is not a delegate type [TokenAuthWebApiCore.Server]
on this line of code:
public virtual void SetUpDataBase(IServiceCollection services)
{
// Add framework services.
services.AddDbContext<SecurityContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("SecurityConnection"), sqlOptions => sqlOptions.MigrationsAssembly("TokenAuthWebApiCore.Server")));
}
This is how I use it:
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(Configuration);
services.AddMvc();
SetUpDataBase(services);
// services.AddDbContext<SecurityContext>(options =>
// options.UseSqlServer(Configuration.GetConnectionString("SecurityConnection"), sqlOptions => sqlOptions.MigrationsAssembly("TokenAuthWebApiCore.Server")));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
public virtual void SetUpDataBase(IServiceCollection services)
{
// Add framework services.
services.AddDbContext<SecurityContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("SecurityConnection"), sqlOptions => sqlOptions.MigrationsAssembly("TokenAuthWebApiCore.Server")));
}
This are all my using statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.IdentityModel.Tokens;
using System.Text;
I am thinking probably this is because the tutorial I am following a tutorial for a different version of .net core and I am using .net core version 2.2. Can you please show me how to fix this? Thank you.
Not about version compatibility error.You need to implement DbContext in your project. When you make context class, you need to inherit context class from DbContext class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With