When I am injecting DbContextOptionsBuilder to CustomTicketStore in ASP.NET core 3.1. I am getting an exception message
Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Authentication.Cookies.ITicketStore Lifetime: Scoped ImplementationType: OneIAM.Services.CustomTicketStore': Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptionsBuilder`1[OneIAM.Data.ApplicationDbContext]' while attempting to activate 'OneIAM.Services.CustomTicketStore'.)
Below is code from the Startup file.
public virtual void ConfigureServices(IServiceCollection services)
{
...
// Persistent ticket/cookie store to provide durable user sessions
services.AddScoped<ITicketStore, CustomTicketStore>();
var optionsBuilder = GetDbContextOptionsBuilder(services);
services.ConfigureApplicationCookie(options =>
{
options.SlidingExpiration = true;
options.SessionStore = new CustomTicketStore(optionsBuilder); <=
});
}
private static DbContextOptionsBuilder<ApplicationDbContext> GetDbContextOptionsBuilder(IServiceCollection services)
{
using (var scope = services.BuildServiceProvider().CreateScope())
{
return scope.ServiceProvider.GetService<DbContextOptionsBuilder<ApplicationDbContext>>();
}
}