Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Threading;
- using System.Threading.Tasks;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Hosting;
- using Heloworld.Services;
- namespace Heloworld
- {
- class Program
- {
- static async Task Main()
- {
- var appCts = new CancellationTokenSource();
- void stopApp() => appCts.Cancel();
- await new HostBuilder()
- .ConfigureServices(services =>
- {
- services.AddScoped(typeof(IHelloWorldService), typeof(HeloWorldService));
- services.AddHostedService(x => new HelloWorldConsoleService(x.GetService<IHelloWorldService>(), stopApp));
- })
- .UseConsoleLifetime(opts => opts.SuppressStatusMessages = true)
- .Build()
- .RunAsync(appCts.Token);
- }
- }
- }
Add Comment
Please, Sign In to add comment