Suddenly my site doesn’t start, it can’t resolve AssesDbContext when resolving IRepoFactory. I’m not sure what’s wrong since all the database services are added at the start of config.
I get the following error:
Cannot resolve ‘SL.Assets.Components.Repo.IRepoFactory’ from root provider because it requires scoped service ‘SL.Assets.Components.Data.AssetsDbContext’.
Config:
_ = builder.Services
.AddHttpContextAccessor()
.AddTransient<IActionContextAccessor, ActionContextAccessor>()
.AddDbContext<AssetsDbContext>(opt => opt.UseSqlServer(AssetsStatics.ConnectionString))
.AddDbContext<AssetsClientDbContext>(opt => opt.UseSqlServer(AssetsStatics.ClientConnectionString))
.AddTransient<IAssetsDbContext, AssetsDbContext>()
.AddTransient<IAssetsClientDbContext, AssetsClientDbContext>()
.AddTransient<IDbContextAccessor, DbContextAccessor>()
.AddTransient<IAssetsConfigAccessor, AssetsConfigAccessor>()
.AddTransient<IExpressionFactory, ExpressionFactory>()
.AddTransient<IClientExpressionFactory, ClientExpressionFactory>()
.AddTransient<ILocalizationAccessor, LocalizationAccessor>()
.AddTransient<IUtilityAccessor, UtilityAccessor>()
.AddTransient<IUrlHelperFactory, UrlHelperFactory>()
.AddTransient<IRepoFactory, RepoFactory>()
.AddTransient<IExpressionFactory, ExpressionFactory>();
RepoFactory:
public interface IRepoFactory
{
IRepoBase this[RepoType type] { get; }
IRepoCoreBase this[RepoCoreType type] { get; }
}
public class RepoFactory(IHttpContextAccessor httpContext, IActionContextAccessor actionContext, IUrlHelperFactory urlHelper, IExpressionFactory expFact, IAssetsConfigAccessor config, IDbContextAccessor dbContext, IWebHostEnvironment environment) : IRepoFactory
{
public IRepoBase this[RepoType type]
{
get
{
....
}
}
public IRepoCoreBase this[RepoCoreType type]
{
get
{
IRepoCoreBase? result = default;
switch(type)
{
case RepoCoreType.TagHelper:
result = new TagHelperRepo(httpContext, actionContext, environment, config.Assets.Config, urlHelper);
break;
}
return result;
}
}
}
Any ideas?