Skip to content

Commit dd164d2

Browse files
committed
removed the DefaultCommand. the simple Command can be used instead.
1 parent 48981b3 commit dd164d2

File tree

9 files changed

+35
-38
lines changed

9 files changed

+35
-38
lines changed

sources/ConsoleTools.Commando.Demo.Autofac.Builder/Commands/DefaultCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.Builder.Commands;
1818

19-
[DefaultCommand(Order = 100, Description = "Default command to be executed when no command name is specified.")]
19+
[Command(Order = 100, Description = "Default command to be executed when no command name is specified.")]
2020
public class DefaultCommand : CommandBase
2121
{
2222
[NamedParameter("text")]

sources/ConsoleTools.Commando.Demo.Autofac.DependencyInjection/Commands/DefaultCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace DustInTheWind.ConsoleTools.Commando.Demo.Autofac.DependencyInjection.Commands;
1818

19-
[DefaultCommand(Order = 100, Description = "Default command to be executed when no command name is specified.")]
19+
[Command(Order = 100, Description = "Default command to be executed when no command name is specified.")]
2020
public class DefaultCommand : CommandBase
2121
{
2222
[NamedParameter("text")]

sources/ConsoleTools.Commando.Demo.Microsoft.Builder/Commands/DefaultCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace DustInTheWind.ConsoleTools.Commando.Demo.Microsoft.Builder.Commands;
1818

19-
[DefaultCommand(Order = 100, Description = "Default command to be executed when no command name is specified.")]
19+
[Command(Order = 100, Description = "Default command to be executed when no command name is specified.")]
2020
public class DefaultCommand : CommandBase
2121
{
2222
[NamedParameter("text")]

sources/ConsoleTools.Commando.Demo.Microsoft.DependencyInjection/Commands/DefaultCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace DustInTheWind.ConsoleTools.Commando.Demo.Microsoft.DependencyInjection.Commands;
1818

19-
[DefaultCommand(Order = 100, Description = "Default command to be executed when no command name is specified.")]
19+
[Command(Order = 100, Description = "Default command to be executed when no command name is specified.")]
2020
public class DefaultCommand : CommandBase
2121
{
2222
[NamedParameter("text")]

sources/ConsoleTools.Commando.Demo.Ninject.Builder/Commands/DefaultCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
namespace DustInTheWind.ConsoleTools.Commando.Demo.Ninject.Builder.Commands;
1818

19-
[DefaultCommand(Order = 100, Description = "Default command to be executed when no command name is specified.")]
19+
[Command(Order = 100, Description = "Default command to be executed when no command name is specified.")]
2020
public class DefaultCommand : CommandBase
2121
{
2222
[NamedParameter("text")]

sources/ConsoleTools.Commando.Setup.Microsoft/ApplicationBuilder.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class ApplicationBuilder
2626
private readonly IServiceCollection serviceCollection;
2727
private readonly CommandMetadataCollection commandMetadataCollection;
2828
private bool isCommandParserConfigured;
29+
private EventHandler<UnhandledApplicationExceptionEventArgs> unhandledExceptionHandler;
2930

3031
public ApplicationBuilder()
3132
{
@@ -115,10 +116,22 @@ public ApplicationBuilder ConfigureServices(Action<IServiceCollection> action)
115116
return this;
116117
}
117118

119+
public ApplicationBuilder HandleExceptions(EventHandler<UnhandledApplicationExceptionEventArgs> eventHandler)
120+
{
121+
unhandledExceptionHandler = eventHandler;
122+
123+
return this;
124+
}
125+
118126
public Application Build()
119127
{
120128
IServiceProvider serviceProvider = FinalizeContainerSetup();
121-
return serviceProvider.GetService<Application>();
129+
Application application = serviceProvider.GetService<Application>();
130+
131+
if (unhandledExceptionHandler != null)
132+
application.UnhandledApplicationException += unhandledExceptionHandler;
133+
134+
return application;
122135
}
123136

124137
private IServiceProvider FinalizeContainerSetup()

sources/ConsoleTools.Commando.Setup.Ninject/ApplicationBuilder.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class ApplicationBuilder
2626
private readonly IKernel kernel;
2727
private readonly CommandMetadataCollection commandMetadataCollection;
2828
private bool isCommandParserConfigured;
29+
private EventHandler<UnhandledApplicationExceptionEventArgs> unhandledExceptionHandler;
2930

3031
private ApplicationBuilder()
3132
{
@@ -110,10 +111,22 @@ public ApplicationBuilder ConfigureServices(Action<IKernel> action)
110111
return this;
111112
}
112113

114+
public ApplicationBuilder HandleExceptions(EventHandler<UnhandledApplicationExceptionEventArgs> eventHandler)
115+
{
116+
unhandledExceptionHandler = eventHandler;
117+
118+
return this;
119+
}
120+
113121
public Application Build()
114122
{
115123
IKernel container = FinalizeContainerSetup();
116-
return container.Get<Application>();
124+
Application application = container.Get<Application>();
125+
126+
if (unhandledExceptionHandler != null)
127+
application.UnhandledApplicationException += unhandledExceptionHandler;
128+
129+
return application;
117130
}
118131

119132
private IKernel FinalizeContainerSetup()

sources/ConsoleTools.Commando/CommandAttribute.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ public class CommandAttribute : Attribute
3636
public bool Enabled { get; set; } = true;
3737

3838
/// <summary>
39-
/// Creates a new instance of the <see cref="CommandAttribute" /> with
40-
/// no name.
39+
/// Creates a new instance of the <see cref="CommandAttribute" /> class.
4140
/// </summary>
42-
protected CommandAttribute()
41+
public CommandAttribute()
4342
{
4443
}
4544
}

sources/ConsoleTools.Commando/DefaultCommandAttribute.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)