Injektion von IHttpContextAccessor in ApplicationDbContext ASP.NET Core 1.0
Ich versuche herauszufinden, wie ich auf den aktuell angemeldeten Benutzernamen außerhalb eines ASP.NET-Controllers zugreifen kann.
Zum Beispiel versuche ich dies zu tun:
Track Felder automatisch mit Entity Framework Code First erstellt und geändert
Um die Verfolgung von Entitäten im @ einzurichtDbContext
.
Hier ist meinApplicationDbContext
aber ich bekomme immer wieder eine Fehlermeldung_httpContextAccessor
istnull
:
private readonly IHttpContextAccessor _httpContextAccessor;
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options, IHttpContextAccessor httpContextAccessor)
: base(options)
{
_httpContextAccessor = httpContextAccessor;
}