Add `dotnet new consoledi` project template
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
### Is your feature request related to a problem? Please describe.
Add `dotnet new consoledi` project template for console app with depenency injection and `IHostBuilder` defaults.
### Describe the solution you'd like
```diff
+ dotnet new consoledi
```
### Additional context
I frequently find myself writing console apps like this:
```csharp
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Services.AddSingleton();
builder.Services.AddSingleton();
// Other registrations...
using IHost host = builder.Build();
await host.Services.GetRequiredService().RunAsync();
```
```csharp
public class ConsoleApplication(IGreeter greeter)
{
public Task RunAsync()
{
greeter.Greet(Environment.UserName);
return Task.CompletedTask;
}
}
```
```csharp
public interface IGreeter
{
void Greet(string userName);
}
```
```csharp
public class Greeter(ILogger logger) : IGreeter
{
public void Greet(string userName) =>
logger.LogInformation("Hello {UserName}!", userName);
}
```
Very similar to basic: https://github.com/dotnet/docs/blob/a265ac4ba40b8cb6a3ecd8abc1b4e35d153e6617/docs/core/extensions/snippets/configuration/console-di-disposable/Program.cs but complete with `appsettings.{environment}.json` and put in non-static class just like `dotnet new worker`.
But always figuring out the template for the current version of .NET is not fun and anyone wanting to use it needs to rediscover it on their own:
- https://stackoverflow.com/q/68392429/19879469
- https://stackoverflow.com/q/66996319/19879469
- https://stackoverflow.com/q/41407221/19879469
So the template would make it easier and might even lead some people to start using it in their console apps. Additionally, it would be great for quick demos, experiments, learning, and such.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.