Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DbContextActivator instead of System.Activator #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/AutoCrudAdmin/AutoCrudAdmin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0"/>
<PackageReference Include="NonFactors.Grid.Core.Mvc6" Version="6.2.4"/>
</ItemGroup>

Expand Down
5 changes: 3 additions & 2 deletions src/AutoCrudAdmin/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace AutoCrudAdmin.Extensions;
using AutoCrudAdmin.Helpers;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using static AutoCrudAdmin.Constants.Entity;

/// <summary>
Expand Down Expand Up @@ -149,11 +150,11 @@ public static bool IsNavigationProperty(this Type type)
public static bool IsEnumerableExceptString(this Type type)
=> typeof(IEnumerable).IsAssignableFrom(type) && type != typeof(string);

private static DbContext? CreateDbContext(Type type)
private static DbContext? CreateDbContext(Type dbContextType)
{
try
{
return Activator.CreateInstance(type) as DbContext;
return DbContextActivator.CreateInstance(dbContextType);
}
catch
{
Expand Down