-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to support a menu system (#1)
- Loading branch information
Showing
10 changed files
with
315 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Shane32.ConsoleDI; | ||
|
||
namespace ExampleConsoleApp2 | ||
{ | ||
[MainMenu("App1")] | ||
class App | ||
{ | ||
private readonly Random _rng; | ||
|
||
public App(Random rng) | ||
{ | ||
_rng = rng; | ||
} | ||
|
||
public async Task RunAsync() | ||
{ | ||
Console.WriteLine($"Generating a random number via Dependency Injection: {_rng.Next(1, 100)}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Shane32.ConsoleDI; | ||
|
||
namespace ExampleConsoleApp2 | ||
{ | ||
[MainMenu("App2")] | ||
class App2 : IMenuOption | ||
{ | ||
public async Task RunAsync() | ||
{ | ||
Console.WriteLine("This is an alternate program"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<IsPackable>false</IsPackable> | ||
<UserSecretsId>89bb3662-9213-4cf1-ae49-8ebf1fafa77a</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.9" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Shane32.ConsoleDI\Shane32.ConsoleDI.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
using Shane32.ConsoleDI; | ||
|
||
namespace ExampleConsoleApp2 | ||
{ | ||
class Program | ||
{ | ||
static async Task Main(string[] args) | ||
=> await ConsoleHost.RunMainMenu(args, CreateHostBuilder, "Demonstration console app with menu"); | ||
|
||
// this function is necessary for Entity Framework Core tools to perform migrations, etc | ||
// do not change signature!! | ||
public static IHostBuilder CreateHostBuilder(string[] args) | ||
=> ConsoleHost.CreateHostBuilder(args, ConfigureServices); | ||
|
||
private static void ConfigureServices(HostBuilderContext context, IServiceCollection services) | ||
{ | ||
// register your Entity Framework data contexts here | ||
|
||
services.AddScoped<Random>(_ => { | ||
var seedStr = context.Configuration["Config:Seed"]; | ||
if (int.TryParse(seedStr, out int seed)) { | ||
return new Random(seed); | ||
} | ||
return new Random(); | ||
}); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Shane32.ConsoleDI | ||
{ | ||
public interface IMenuOption | ||
{ | ||
public Task RunAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Shane32.ConsoleDI | ||
{ | ||
[AttributeUsage(AttributeTargets.Class)] | ||
public class MainMenuAttribute : Attribute | ||
{ | ||
public string Name { get; set; } | ||
public MainMenuAttribute(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
public int SortOrder { get; set; } | ||
} | ||
} |