diff --git a/src/EFCore.Design/Design/Internal/AppServiceProviderFactory.cs b/src/EFCore.Design/Design/Internal/AppServiceProviderFactory.cs index 360c325b403..57b9b0621dc 100644 --- a/src/EFCore.Design/Design/Internal/AppServiceProviderFactory.cs +++ b/src/EFCore.Design/Design/Internal/AppServiceProviderFactory.cs @@ -44,7 +44,7 @@ public virtual IServiceProvider Create([NotNull] string[] args) _reporter.WriteVerbose(DesignStrings.FindingServiceProvider); return CreateFromHosting(args) - ?? CreateArgsServiceProvider(args); + ?? CreateEmptyServiceProvider(); } private IServiceProvider CreateFromHosting(string[] args) @@ -97,13 +97,11 @@ private IServiceProvider CreateFromHosting(string[] args) } } - private IServiceProvider CreateArgsServiceProvider(string[] args) + private IServiceProvider CreateEmptyServiceProvider() { _reporter.WriteVerbose(DesignStrings.NoServiceProvider); - return new ServiceCollection() - .AddScoped(typeof(string[]), sp => args) - .BuildServiceProvider(); + return new ServiceCollection().BuildServiceProvider(); } } } diff --git a/src/EFCore.Design/Design/Internal/DatabaseOperations.cs b/src/EFCore.Design/Design/Internal/DatabaseOperations.cs index 77033f82a00..5875d8a59d9 100644 --- a/src/EFCore.Design/Design/Internal/DatabaseOperations.cs +++ b/src/EFCore.Design/Design/Internal/DatabaseOperations.cs @@ -25,6 +25,7 @@ public class DatabaseOperations private readonly string _rootNamespace; private readonly string _language; private readonly DesignTimeServicesBuilder _servicesBuilder; + private readonly string[] _args; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -51,6 +52,7 @@ public DatabaseOperations( _projectDir = projectDir; _rootNamespace = rootNamespace; _language = language; + _args = args; _servicesBuilder = new DesignTimeServicesBuilder(assembly, startupAssembly, reporter, args); } diff --git a/src/EFCore.Design/Design/Internal/MigrationsOperations.cs b/src/EFCore.Design/Design/Internal/MigrationsOperations.cs index 24364a798ff..f9a0cf1048f 100644 --- a/src/EFCore.Design/Design/Internal/MigrationsOperations.cs +++ b/src/EFCore.Design/Design/Internal/MigrationsOperations.cs @@ -32,6 +32,7 @@ public class MigrationsOperations private readonly string _language; private readonly DesignTimeServicesBuilder _servicesBuilder; private readonly DbContextOperations _contextOperations; + private readonly string[] _args; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -60,6 +61,7 @@ public MigrationsOperations( _projectDir = projectDir; _rootNamespace = rootNamespace; _language = language; + _args = args; _contextOperations = new DbContextOperations( reporter, assembly, diff --git a/src/EFCore.Design/Design/OperationExecutor.cs b/src/EFCore.Design/Design/OperationExecutor.cs index d9d20ca468b..2227eb31fca 100644 --- a/src/EFCore.Design/Design/OperationExecutor.cs +++ b/src/EFCore.Design/Design/OperationExecutor.cs @@ -48,7 +48,7 @@ public class OperationExecutor : MarshalByRefObject /// projectDir--The target project's root directory. /// rootNamespace--The target project's root namespace. /// language--The programming language to be used to generate classes. - /// appArgs--Extra arguments passed into the operation. + /// remainingArguments--Extra arguments passed into the operation. /// /// The . /// The executor arguments. @@ -63,7 +63,7 @@ public OperationExecutor([NotNull] IOperationReportHandler reportHandler, [NotNu _projectDir = (string)args["projectDir"]; _rootNamespace = (string)args["rootNamespace"]; _language = (string)args["language"]; - _designArgs = (string[])args["appArgs"]; + _designArgs = (string[])args["remainingArguments"]; var toolsVersion = (string)args["toolsVersion"]; var runtimeVersion = ProductInfo.GetVersion(); diff --git a/src/dotnet-ef/RootCommand.cs b/src/dotnet-ef/RootCommand.cs index b95810d0cbd..f47bd395ef1 100644 --- a/src/dotnet-ef/RootCommand.cs +++ b/src/dotnet-ef/RootCommand.cs @@ -53,7 +53,7 @@ public override void Configure(CommandLineApplication command) _command = command; } - protected override int Execute() + protected override int Execute(string[] _) { var commands = _args.TakeWhile(a => a[0] != '-').ToList(); if (_help.HasValue() diff --git a/src/ef/AppDomainOperationExecutor.cs b/src/ef/AppDomainOperationExecutor.cs index cdd7ab4e102..acf58cde203 100644 --- a/src/ef/AppDomainOperationExecutor.cs +++ b/src/ef/AppDomainOperationExecutor.cs @@ -24,8 +24,9 @@ public AppDomainOperationExecutor( string projectDir, string dataDirectory, string rootNamespace, - string language) - : base(assembly, startupAssembly, projectDir, rootNamespace, language) + string language, + string[] remainingArguments) + : base(assembly, startupAssembly, projectDir, rootNamespace, language, remainingArguments) { var info = new AppDomainSetup { ApplicationBase = AppBasePath }; @@ -66,7 +67,8 @@ public AppDomainOperationExecutor( { "projectDir", ProjectDirectory }, { "rootNamespace", RootNamespace }, { "language", Language }, - { "toolsVersion", ProductInfo.GetVersion() } + { "toolsVersion", ProductInfo.GetVersion() }, + { "remainingArguments", RemainingArguments } } }, null, diff --git a/src/ef/CommandLineUtils/CommandLineApplication.cs b/src/ef/CommandLineUtils/CommandLineApplication.cs index d3f0eac296d..569f5003d5e 100644 --- a/src/ef/CommandLineUtils/CommandLineApplication.cs +++ b/src/ef/CommandLineUtils/CommandLineApplication.cs @@ -27,14 +27,14 @@ private enum ParseOptionResult // remaining arguments, including the first unexpected argument, will be stored in RemainingArguments property. private readonly bool _throwOnUnexpectedArg; - public CommandLineApplication(bool throwOnUnexpectedArg = true) + public CommandLineApplication(bool throwOnUnexpectedArg = false) { _throwOnUnexpectedArg = throwOnUnexpectedArg; Options = new List(); Arguments = new List(); Commands = new List(); RemainingArguments = new List(); - Invoke = () => 0; + Invoke = (args) => 0; } public CommandLineApplication Parent { get; set; } @@ -48,7 +48,7 @@ public CommandLineApplication(bool throwOnUnexpectedArg = true) public List Arguments { get; } public List RemainingArguments { get; } public bool IsShowingInformation { get; protected set; } // Is showing help or version? - public Func Invoke { get; set; } + public Func Invoke { get; set; } public Func LongVersionGetter { get; set; } public Func ShortVersionGetter { get; set; } public List Commands { get; } @@ -62,7 +62,7 @@ public CommandLineApplication Command(string name, bool throwOnUnexpectedArg = t public CommandLineApplication Command( string name, Action configuration, - bool throwOnUnexpectedArg = true) + bool throwOnUnexpectedArg = false) { var command = new CommandLineApplication(throwOnUnexpectedArg) { Name = name, Parent = this }; Commands.Add(command); @@ -98,9 +98,9 @@ public CommandArgument Argument(string name, string description, Action invoke) => Invoke = invoke; + public void OnExecute(Func invoke) => Invoke = invoke; - public void OnExecute(Func> invoke) => Invoke = () => invoke().Result; + public void OnExecute(Func> invoke) => Invoke = (args) => invoke(args).Result; public int Execute(params string[] args) { @@ -158,7 +158,7 @@ public int Execute(params string[] args) } } - return command.Invoke(); + return command.Invoke(command.RemainingArguments.ToArray()); } private ParseOptionResult ParseOption( diff --git a/src/ef/Commands/CommandBase.cs b/src/ef/Commands/CommandBase.cs index 1c708c7352e..b857de3f665 100644 --- a/src/ef/Commands/CommandBase.cs +++ b/src/ef/Commands/CommandBase.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System.Collections.Generic; +using JetBrains.Annotations; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.EntityFrameworkCore.Tools.Properties; @@ -9,8 +9,6 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands { internal abstract class CommandBase { - protected string[] RemainingArguments { get; private set; } - public virtual void Configure(CommandLineApplication command) { var verbose = command.Option("-v|--verbose", Resources.VerboseDescription); @@ -18,10 +16,9 @@ public virtual void Configure(CommandLineApplication command) var prefixOutput = command.Option("--prefix-output", Resources.PrefixDescription); command.HandleResponseFiles = true; - RemainingArguments = command.RemainingArguments.ToArray(); command.OnExecute( - () => + (args) => { Reporter.IsVerbose = verbose.HasValue(); Reporter.NoColor = noColor.HasValue(); @@ -29,7 +26,7 @@ public virtual void Configure(CommandLineApplication command) Validate(); - return Execute(); + return Execute(args); }); } @@ -37,7 +34,7 @@ protected virtual void Validate() { } - protected virtual int Execute() + protected virtual int Execute([NotNull] string[] args) => 0; } } diff --git a/src/ef/Commands/DatabaseDropCommand.cs b/src/ef/Commands/DatabaseDropCommand.cs index 30f73f5ed7c..527ae31ef22 100644 --- a/src/ef/Commands/DatabaseDropCommand.cs +++ b/src/ef/Commands/DatabaseDropCommand.cs @@ -9,13 +9,13 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class DatabaseDropCommand { - protected override int Execute() + protected override int Execute(string[] args) { - var executor = CreateExecutor(); + var executor = CreateExecutor(args); void LogDropCommand(Func resource) { - var result = executor.GetContextInfo(Context.Value(), RemainingArguments); + var result = executor.GetContextInfo(Context.Value()); var databaseName = result["DatabaseName"] as string; var dataSource = result["DataSource"] as string; Reporter.WriteInformation(resource(databaseName, dataSource)); @@ -38,9 +38,9 @@ void LogDropCommand(Func resource) } } - executor.DropDatabase(Context.Value(), RemainingArguments); + executor.DropDatabase(Context.Value()); - return base.Execute(); + return base.Execute(args); } } } diff --git a/src/ef/Commands/DatabaseUpdateCommand.cs b/src/ef/Commands/DatabaseUpdateCommand.cs index 79edd47626f..06db58b40ea 100644 --- a/src/ef/Commands/DatabaseUpdateCommand.cs +++ b/src/ef/Commands/DatabaseUpdateCommand.cs @@ -6,11 +6,11 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class DatabaseUpdateCommand { - protected override int Execute() + protected override int Execute(string[] args) { - CreateExecutor().UpdateDatabase(_migration.Value, _connection.Value(), Context.Value(), RemainingArguments); + CreateExecutor(args).UpdateDatabase(_migration.Value, _connection.Value(), Context.Value()); - return base.Execute(); + return base.Execute(args); } } } diff --git a/src/ef/Commands/DbContextInfoCommand.cs b/src/ef/Commands/DbContextInfoCommand.cs index 768c8dac278..9fb3fd5f93d 100644 --- a/src/ef/Commands/DbContextInfoCommand.cs +++ b/src/ef/Commands/DbContextInfoCommand.cs @@ -9,9 +9,9 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class DbContextInfoCommand { - protected override int Execute() + protected override int Execute(string[] args) { - var result = CreateExecutor().GetContextInfo(Context.Value(), RemainingArguments); + var result = CreateExecutor(args).GetContextInfo(Context.Value()); if (_json.HasValue()) { @@ -22,7 +22,7 @@ protected override int Execute() ReportResult(result); } - return base.Execute(); + return base.Execute(args); } private static void ReportJsonResult(IDictionary result) diff --git a/src/ef/Commands/DbContextListCommand.cs b/src/ef/Commands/DbContextListCommand.cs index 921b9a7bceb..f48cc36768a 100644 --- a/src/ef/Commands/DbContextListCommand.cs +++ b/src/ef/Commands/DbContextListCommand.cs @@ -11,9 +11,9 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class DbContextListCommand { - protected override int Execute() + protected override int Execute(string[] args) { - var types = CreateExecutor().GetContextTypes().ToList(); + var types = CreateExecutor(args).GetContextTypes().ToList(); if (_json.HasValue()) { @@ -24,7 +24,7 @@ protected override int Execute() ReportResults(types); } - return base.Execute(); + return base.Execute(args); } private static void ReportJsonResults(IReadOnlyList contextTypes) diff --git a/src/ef/Commands/DbContextScaffoldCommand.cs b/src/ef/Commands/DbContextScaffoldCommand.cs index 04e7dc2736b..565ae5bf578 100644 --- a/src/ef/Commands/DbContextScaffoldCommand.cs +++ b/src/ef/Commands/DbContextScaffoldCommand.cs @@ -25,9 +25,9 @@ protected override void Validate() } } - protected override int Execute() + protected override int Execute(string[] args) { - var result = CreateExecutor().ScaffoldContext( + var result = CreateExecutor(args).ScaffoldContext( _provider.Value, _connection.Value, _outputDir.Value(), @@ -39,14 +39,13 @@ protected override int Execute() _force.HasValue(), _useDatabaseNames.HasValue(), _namespace.Value(), - _contextNamespace.Value(), - RemainingArguments); + _contextNamespace.Value()); if (_json.HasValue()) { ReportJsonResults(result); } - return base.Execute(); + return base.Execute(args); } private static void ReportJsonResults(IDictionary result) diff --git a/src/ef/Commands/DbContextScriptCommand.cs b/src/ef/Commands/DbContextScriptCommand.cs index b42ff0f70c7..7c9a47ae8d6 100644 --- a/src/ef/Commands/DbContextScriptCommand.cs +++ b/src/ef/Commands/DbContextScriptCommand.cs @@ -10,10 +10,9 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class DbContextScriptCommand { - protected override int Execute() + protected override int Execute(string[] args) { - var sql = CreateExecutor().ScriptDbContext( - Context.Value(), RemainingArguments); + var sql = CreateExecutor(args).ScriptDbContext(Context.Value()); if (!_output.HasValue()) { @@ -37,7 +36,7 @@ protected override int Execute() File.WriteAllText(output, sql, Encoding.UTF8); } - return base.Execute(); + return base.Execute(args); } } } diff --git a/src/ef/Commands/HelpCommandBase.cs b/src/ef/Commands/HelpCommandBase.cs index 42d3d648c00..6a05df3eedf 100644 --- a/src/ef/Commands/HelpCommandBase.cs +++ b/src/ef/Commands/HelpCommandBase.cs @@ -16,11 +16,11 @@ public override void Configure(CommandLineApplication command) base.Configure(command); } - protected override int Execute() + protected override int Execute(string[] args) { _command.ShowHelp(); - return base.Execute(); + return base.Execute(args); } } } diff --git a/src/ef/Commands/MigrationsAddCommand.cs b/src/ef/Commands/MigrationsAddCommand.cs index abbe770ea79..9d15801dc9d 100644 --- a/src/ef/Commands/MigrationsAddCommand.cs +++ b/src/ef/Commands/MigrationsAddCommand.cs @@ -19,10 +19,10 @@ protected override void Validate() } } - protected override int Execute() + protected override int Execute(string[] args) { - var files = CreateExecutor().AddMigration( - _name.Value, _outputDir.Value(), Context.Value(), _namespace.Value(), RemainingArguments); + var files = CreateExecutor(args) + .AddMigration(_name.Value, _outputDir.Value(), Context.Value(), _namespace.Value()); if (_json.HasValue()) { @@ -33,7 +33,7 @@ protected override int Execute() Reporter.WriteInformation(Resources.MigrationsAddCompleted); } - return base.Execute(); + return base.Execute(args); } private static void ReportJson(IDictionary files) diff --git a/src/ef/Commands/MigrationsListCommand.cs b/src/ef/Commands/MigrationsListCommand.cs index 21f686550b1..f5bc56d521e 100644 --- a/src/ef/Commands/MigrationsListCommand.cs +++ b/src/ef/Commands/MigrationsListCommand.cs @@ -11,10 +11,10 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class MigrationsListCommand { - protected override int Execute() + protected override int Execute(string[] args) { - var migrations = CreateExecutor() - .GetMigrations(Context.Value(), RemainingArguments).ToList(); + var migrations = CreateExecutor(args) + .GetMigrations(Context.Value()).ToList(); if (_json.HasValue()) { @@ -25,7 +25,7 @@ protected override int Execute() ReportResults(migrations); } - return base.Execute(); + return base.Execute(args); } private static void ReportJsonResults(IReadOnlyList migrations) diff --git a/src/ef/Commands/MigrationsRemoveCommand.cs b/src/ef/Commands/MigrationsRemoveCommand.cs index 60944d842fb..7d8cc33ec06 100644 --- a/src/ef/Commands/MigrationsRemoveCommand.cs +++ b/src/ef/Commands/MigrationsRemoveCommand.cs @@ -8,15 +8,16 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class MigrationsRemoveCommand { - protected override int Execute() + protected override int Execute(string[] args) { - var result = CreateExecutor().RemoveMigration(Context.Value(), _force.HasValue(), RemainingArguments); + var result = CreateExecutor(args) + .RemoveMigration(Context.Value(), _force.HasValue()); if (_json.HasValue()) { ReportJsonResults(result); } - return base.Execute(); + return base.Execute(args); } private static void ReportJsonResults(IDictionary result) diff --git a/src/ef/Commands/MigrationsScriptCommand.cs b/src/ef/Commands/MigrationsScriptCommand.cs index 525f5a700ea..e796c45026b 100644 --- a/src/ef/Commands/MigrationsScriptCommand.cs +++ b/src/ef/Commands/MigrationsScriptCommand.cs @@ -10,14 +10,13 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class MigrationsScriptCommand { - protected override int Execute() + protected override int Execute(string[] args) { - var sql = CreateExecutor().ScriptMigration( + var sql = CreateExecutor(args).ScriptMigration( _from.Value, _to.Value, _idempotent.HasValue(), - Context.Value(), - RemainingArguments); + Context.Value()); if (!_output.HasValue()) { @@ -41,7 +40,7 @@ protected override int Execute() File.WriteAllText(output, sql, Encoding.UTF8); } - return base.Execute(); + return base.Execute(args); } } } diff --git a/src/ef/Commands/ProjectCommandBase.cs b/src/ef/Commands/ProjectCommandBase.cs index 4d026c4ccbd..d3bd2e05b63 100644 --- a/src/ef/Commands/ProjectCommandBase.cs +++ b/src/ef/Commands/ProjectCommandBase.cs @@ -43,7 +43,7 @@ protected override void Validate() } } - protected IOperationExecutor CreateExecutor() + protected IOperationExecutor CreateExecutor(string[] remainingArguments) { try { @@ -56,7 +56,8 @@ protected IOperationExecutor CreateExecutor() _projectDir.Value(), _dataDir.Value(), _rootNamespace.Value(), - _language.Value()); + _language.Value(), + remainingArguments); } catch (MissingMethodException) // NB: Thrown with EF Core 3.1 { @@ -70,7 +71,8 @@ protected IOperationExecutor CreateExecutor() _projectDir.Value(), _dataDir.Value(), _rootNamespace.Value(), - _language.Value()); + _language.Value(), + remainingArguments); } catch (FileNotFoundException ex) when (new AssemblyName(ex.FileName).Name == OperationExecutorBase.DesignAssemblyName) diff --git a/src/ef/Commands/RootCommand.cs b/src/ef/Commands/RootCommand.cs index 0fc96811eba..8a78cefc037 100644 --- a/src/ef/Commands/RootCommand.cs +++ b/src/ef/Commands/RootCommand.cs @@ -25,7 +25,7 @@ public override void Configure(CommandLineApplication command) base.Configure(command); } - protected override int Execute() + protected override int Execute(string[] args) { Reporter.WriteInformation( string.Join( @@ -39,7 +39,7 @@ protected override int Execute() Reporter.Colorize(@" |___||_| / \\\/\\", s => s.Insert(33, Reset).Insert(23, Bold + Gray).Insert(8, Dark + Magenta)), string.Empty)); - return base.Execute(); + return base.Execute(args); } private static string GetVersion() diff --git a/src/ef/IOperationExecutor.cs b/src/ef/IOperationExecutor.cs index 032180d5090..55983184ab1 100644 --- a/src/ef/IOperationExecutor.cs +++ b/src/ef/IOperationExecutor.cs @@ -9,12 +9,12 @@ namespace Microsoft.EntityFrameworkCore.Tools { internal interface IOperationExecutor : IDisposable { - IDictionary AddMigration(string name, string outputDir, string contextType, string @namespace, string[] remainingArguments); - IDictionary RemoveMigration(string contextType, bool force, string[] remainingArguments); - IEnumerable GetMigrations(string contextType, string[] remainingArguments); - void DropDatabase(string contextType, string[] remainingArguments); - IDictionary GetContextInfo(string name, string[] remainingArguments); - void UpdateDatabase(string migration, string connectionString, string contextType, string[] remainingArguments); + IDictionary AddMigration(string name, string outputDir, string contextType, string @namespace); + IDictionary RemoveMigration(string contextType, bool force); + IEnumerable GetMigrations(string contextType); + void DropDatabase(string contextType); + IDictionary GetContextInfo(string name); + void UpdateDatabase(string migration, string connectionString, string contextType); IEnumerable GetContextTypes(); IDictionary ScaffoldContext( @@ -29,11 +29,10 @@ IDictionary ScaffoldContext( bool overwriteFiles, bool useDatabaseNames, string entityNamespace, - string dbContextNamespace, - string[] remainingArguments); + string dbContextNamespace); - string ScriptMigration(string fromMigration, string toMigration, bool idempotent, string contextType, string[] remainingArguments); + string ScriptMigration(string fromMigration, string toMigration, bool idempotent, string contextType); - string ScriptDbContext(string contextType, string[] remainingArguments); + string ScriptDbContext(string contextType); } } diff --git a/src/ef/OperationExecutorBase.cs b/src/ef/OperationExecutorBase.cs index 367d0060c04..609076ac528 100644 --- a/src/ef/OperationExecutorBase.cs +++ b/src/ef/OperationExecutorBase.cs @@ -21,13 +21,15 @@ internal abstract class OperationExecutorBase : IOperationExecutor protected string ProjectDirectory { get; } protected string RootNamespace { get; } protected string Language { get; } + protected string[] RemainingArguments { get; } protected OperationExecutorBase( string assembly, string startupAssembly, string projectDir, string rootNamespace, - string language) + string language, + string[] remainingArguments) { AssemblyFileName = Path.GetFileNameWithoutExtension(assembly); StartupAssemblyFileName = startupAssembly == null @@ -40,6 +42,7 @@ protected OperationExecutorBase( RootNamespace = rootNamespace ?? AssemblyFileName; ProjectDirectory = projectDir ?? Directory.GetCurrentDirectory(); Language = language; + RemainingArguments = remainingArguments ?? new string[0]; Reporter.WriteVerbose(Resources.UsingAssembly(AssemblyFileName)); Reporter.WriteVerbose(Resources.UsingStartupAssembly(StartupAssemblyFileName)); @@ -47,6 +50,7 @@ protected OperationExecutorBase( Reporter.WriteVerbose(Resources.UsingWorkingDirectory(Directory.GetCurrentDirectory())); Reporter.WriteVerbose(Resources.UsingRootNamespace(RootNamespace)); Reporter.WriteVerbose(Resources.UsingProjectDir(ProjectDirectory)); + Reporter.WriteVerbose(Resources.RemainingArguments(string.Join(",", RemainingArguments))); } public virtual void Dispose() @@ -82,7 +86,7 @@ private object InvokeOperationImpl(string operationName, IDictionary arguments) return resultHandler.Result; } - public IDictionary AddMigration(string name, string outputDir, string contextType, string @namespace, string[] remainingArguments) + public IDictionary AddMigration(string name, string outputDir, string contextType, string @namespace) => InvokeOperation( "AddMigration", new Dictionary @@ -90,39 +94,37 @@ public IDictionary AddMigration(string name, string outputDir, string contextTyp ["name"] = name, ["outputDir"] = outputDir, ["contextType"] = contextType, - ["namespace"] = @namespace, - ["appArgs"] = remainingArguments + ["namespace"] = @namespace }); - public IDictionary RemoveMigration(string contextType, bool force, string[] remainingArguments) + public IDictionary RemoveMigration(string contextType, bool force) => InvokeOperation( "RemoveMigration", - new Dictionary { ["contextType"] = contextType, ["force"] = force, ["appArgs"] = remainingArguments }); + new Dictionary { ["contextType"] = contextType, ["force"] = force }); - public IEnumerable GetMigrations(string contextType, string[] remainingArguments) + public IEnumerable GetMigrations(string contextType) => InvokeOperation>( "GetMigrations", - new Dictionary { ["contextType"] = contextType, ["appArgs"] = remainingArguments }); + new Dictionary { ["contextType"] = contextType }); - public void DropDatabase(string contextType, string[] remainingArguments) + public void DropDatabase(string contextType) => InvokeOperation( "DropDatabase", - new Dictionary { ["contextType"] = contextType, ["appArgs"] = remainingArguments }); + new Dictionary { ["contextType"] = contextType }); - public IDictionary GetContextInfo(string name, string[] remainingArguments) + public IDictionary GetContextInfo(string name) => InvokeOperation( "GetContextInfo", - new Dictionary { ["contextType"] = name, ["appArgs"] = remainingArguments }); + new Dictionary { ["contextType"] = name }); - public void UpdateDatabase(string migration, string connectionString, string contextType, string[] remainingArguments) + public void UpdateDatabase(string migration, string connectionString, string contextType) => InvokeOperation( "UpdateDatabase", new Dictionary { ["targetMigration"] = migration, ["connectionString"] = connectionString, - ["contextType"] = contextType, - ["appArgs"] = remainingArguments + ["contextType"] = contextType }); public IEnumerable GetContextTypes() @@ -140,8 +142,7 @@ public IDictionary ScaffoldContext( bool overwriteFiles, bool useDatabaseNames, string modelNamespace, - string contextNamespace, - string[] remainingArguments) + string contextNamespace) => InvokeOperation( "ScaffoldContext", new Dictionary @@ -157,16 +158,14 @@ public IDictionary ScaffoldContext( ["overwriteFiles"] = overwriteFiles, ["useDatabaseNames"] = useDatabaseNames, ["modelNamespace"] = modelNamespace, - ["contextNamespace"] = contextNamespace, - ["appArgs"] = remainingArguments + ["contextNamespace"] = contextNamespace }); public string ScriptMigration( string fromMigration, string toMigration, bool idempotent, - string contextType, - string[] remainingArguments) + string contextType) => InvokeOperation( "ScriptMigration", new Dictionary @@ -174,13 +173,12 @@ public string ScriptMigration( ["fromMigration"] = fromMigration, ["toMigration"] = toMigration, ["idempotent"] = idempotent, - ["contextType"] = contextType, - ["appArgs"] = remainingArguments + ["contextType"] = contextType }); - public string ScriptDbContext(string contextType, string[] remainingArguments) + public string ScriptDbContext(string contextType) => InvokeOperation( "ScriptDbContext", - new Dictionary { ["contextType"] = contextType, ["appArgs"] = remainingArguments }); + new Dictionary { ["contextType"] = contextType }); } } diff --git a/src/ef/Properties/Resources.Designer.cs b/src/ef/Properties/Resources.Designer.cs index c07a37eb9ca..05fb7b14dbf 100644 --- a/src/ef/Properties/Resources.Designer.cs +++ b/src/ef/Properties/Resources.Designer.cs @@ -514,6 +514,14 @@ public static string ContextNamespaceDescription public static string MigrationsNamespaceDescription => GetString("MigrationsNamespaceDescription"); + /// + /// Remaining arguments: '{remainingArguments}'. + /// + public static string RemainingArguments([CanBeNull] object remainingArguments) + => string.Format( + GetString("RemainingArguments", nameof(remainingArguments)), + remainingArguments); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/ef/Properties/Resources.resx b/src/ef/Properties/Resources.resx index 6e1fd490e85..afb2a1ce634 100644 --- a/src/ef/Properties/Resources.resx +++ b/src/ef/Properties/Resources.resx @@ -342,4 +342,7 @@ Specify to override the namespace for the migration. + + Remaining arguments: '{remainingArguments}'. + \ No newline at end of file diff --git a/src/ef/ReflectionOperationExecutor.cs b/src/ef/ReflectionOperationExecutor.cs index 54e60e63ff3..cd240a31e47 100644 --- a/src/ef/ReflectionOperationExecutor.cs +++ b/src/ef/ReflectionOperationExecutor.cs @@ -25,8 +25,9 @@ public ReflectionOperationExecutor( string projectDir, string dataDirectory, string rootNamespace, - string language) - : base(assembly, startupAssembly, projectDir, rootNamespace, language) + string language, + string[] remainingArguments) + : base(assembly, startupAssembly, projectDir, rootNamespace, language, remainingArguments) { if (dataDirectory != null) { @@ -49,14 +50,15 @@ public ReflectionOperationExecutor( _executor = Activator.CreateInstance( _commandsAssembly.GetType(ExecutorTypeName, throwOnError: true, ignoreCase: false), reportHandler, - new Dictionary + new Dictionary { { "targetName", AssemblyFileName }, { "startupTargetName", StartupAssemblyFileName }, { "projectDir", ProjectDirectory }, { "rootNamespace", RootNamespace }, { "language", Language }, - { "toolsVersion", ProductInfo.GetVersion() } + { "toolsVersion", ProductInfo.GetVersion() }, + { "remainingArguments", RemainingArguments } }); _resultHandlerType = _commandsAssembly.GetType(ResultHandlerTypeName, throwOnError: true, ignoreCase: false); diff --git a/test/EFCore.Design.Tests/Design/DbContextActivatorTest.cs b/test/EFCore.Design.Tests/Design/DbContextActivatorTest.cs index 0773508db76..cc905008f59 100644 --- a/test/EFCore.Design.Tests/Design/DbContextActivatorTest.cs +++ b/test/EFCore.Design.Tests/Design/DbContextActivatorTest.cs @@ -15,19 +15,6 @@ public void CreateInstance_works() Assert.IsType(result); } - [ConditionalFact] - public void CreateInstance_can_pass_in_arguments() - { - var result = DbContextActivator.CreateInstance( - typeof(ArgsContext), arguments: new string[] { "Pass", "Me", "In" }); - - Assert.IsType(result); - Assert.Collection(((ArgsContext)result).Args, - s => { Assert.Equal("Pass", s); }, - s => { Assert.Equal("Me", s); }, - s => { Assert.Equal("In", s); }); - } - private class TestContext : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder options) @@ -35,20 +22,5 @@ protected override void OnConfiguring(DbContextOptionsBuilder options) .EnableServiceProviderCaching(false) .UseInMemoryDatabase(nameof(DbContextActivatorTest)); } - - private class ArgsContext : DbContext - { - public string[] Args { get; set; } - - public ArgsContext(string[] args) - { - Args = args; - } - - protected override void OnConfiguring(DbContextOptionsBuilder options) - => options - .EnableServiceProviderCaching(false) - .UseInMemoryDatabase(nameof(DbContextActivatorTest)); - } } }