Код: Выделить всё
builder.Services.AddDbContext((_, options) =>
{
// some configuration
}, ServiceLifetime.Transient);
builder.Services.AddDbContext((_, options) =>
{
// the exact same configuration
}, ServiceLifetime.Transient);
Мне бы хотелось у меня есть возможность каждый раз перебирать все DbContexts, так что вероятность того, что я забуду зарегистрировать один из них, меньше. Примерно так:
Код: Выделить всё
public static void DoWithEachRegisteredDbContext(DoWithDbContext magic)
{
magic();
magic();
}
public delegate Type[] DoWithDbContext();
// and this method is called like this for the above example
DoWithEachRegisteredDbContext(AddDbContext);
public Type[] AddDbContext() {
builder.Services.AddDbContext((_, options) =>
{
// some configuration
}, ServiceLifetime.Transient);
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... -parameter