Update DbContextFactory.cs (#22807)

pull/22806/head
Adam Radocz 2021-07-23 23:05:01 +02:00 committed by GitHub
parent a6617ada1c
commit 3bf01c99ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 11 deletions

View File

@ -11,18 +11,12 @@ namespace BlazorServerDbContextExample.Data
public DbContextFactory(IServiceProvider provider)
{
this.provider = provider;
this.provider = provider ?? throw new ArgumentNullException(
$"{nameof(provider)}: You must configure an instance of " +
"IServiceProvider");
}
public TContext CreateDbContext()
{
if (provider == null)
{
throw new InvalidOperationException(
$"You must configure an instance of IServiceProvider");
}
return ActivatorUtilities.CreateInstance<TContext>(provider);
}
public TContext CreateDbContext() =>
ActivatorUtilities.CreateInstance<TContext>(provider);
}
}