From 3bf01c99ffc0db7c7eeb2113c4bf44cc75dab76d Mon Sep 17 00:00:00 2001 From: Adam Radocz Date: Fri, 23 Jul 2021 23:05:01 +0200 Subject: [PATCH] Update DbContextFactory.cs (#22807) --- .../Data/DbContextFactory.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/aspnetcore/blazor/common/samples/3.x/BlazorServerEFCoreSample/BlazorServerDbContextExample/Data/DbContextFactory.cs b/aspnetcore/blazor/common/samples/3.x/BlazorServerEFCoreSample/BlazorServerDbContextExample/Data/DbContextFactory.cs index 1c5a14340d..cff1400154 100644 --- a/aspnetcore/blazor/common/samples/3.x/BlazorServerEFCoreSample/BlazorServerDbContextExample/Data/DbContextFactory.cs +++ b/aspnetcore/blazor/common/samples/3.x/BlazorServerEFCoreSample/BlazorServerDbContextExample/Data/DbContextFactory.cs @@ -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(provider); - } + public TContext CreateDbContext() => + ActivatorUtilities.CreateInstance(provider); } }