Skip to content
Merged
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
16 changes: 1 addition & 15 deletions Mongo.Migration/Migrations/Locators/MigrationLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,7 @@ private static List<Assembly> GetAssemblies()

private TMigrationType GetMigrationInstance(Type type)
{
ConstructorInfo[] constructors = type.GetConstructors();

if (constructors.Length > 0)
{
var args = constructors
.First()
.GetParameters()
.Select(parameterInfo => _serviceProvider.GetRequiredService(parameterInfo.ParameterType))
.ToArray();

return Activator.CreateInstance(type, args) as TMigrationType
?? throw new InvalidOperationException($"Cannot create {type} migration");
}

return Activator.CreateInstance(type) as TMigrationType
return ActivatorUtilities.CreateInstance(_serviceProvider, type) as TMigrationType
?? throw new InvalidOperationException($"Cannot create {type} migration");
}
}