Код: Выделить всё
public static class MyHtmlExtensions
{
public static IHtmlContent MyHelper(this IHtmlHelper helper, …)
{
//How do I go about defining _factory, given that this class is static?
DbContextFactory _factory = new();
//The serviceProvider argument is missing here, hence compiler error CS7036)
DALsomething _dal = new DALsomething(_factory);
}
}
Код: Выделить всё
var _ConnectionString = builder.Configuration.GetConnectionString("MyDbConnectionString");
builder.Services.AddDbContextFactory(x => x.UseSqlServer(_ConnectionString), ServiceLifetime.Scoped);
Код: Выделить всё
public abstract class dalBaseClass
{
public readonly IDbContextFactory _factory;
public dalBaseClass(IDbContextFactory dbContextFactory)
{
_factory = dbContextFactory;
}
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... the-latter
Мобильная версия