Skip to content

Commit

Permalink
Simplify service by using singletons
Browse files Browse the repository at this point in the history
  • Loading branch information
nabsul committed Feb 12, 2022
1 parent b3ddd41 commit 6248f72
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((ctx, cfg) => cfg.AddEnvironmentVariables())
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>())
.ConfigureServices(services => services.AddHostedService<RenewalServiceWrapper>())
.ConfigureServices(services => services.AddHostedService<RenewalService>())
.Build().Run();
1 change: 0 additions & 1 deletion Services/KCertClient.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using k8s.Models;
using KCert.Models;
using Microsoft.Extensions.Logging;
using Microsoft.Rest;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
29 changes: 0 additions & 29 deletions Services/RenewalServiceWrapper.cs

This file was deleted.

10 changes: 8 additions & 2 deletions Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Linq;
using System.Reflection;

Expand Down Expand Up @@ -33,8 +34,13 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

private static void AddKCertServices(IServiceCollection services)
{
Console.WriteLine("Adding KCert services");
var serviceTypes = Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.GetCustomAttribute<ServiceAttribute>() != null)
.Select(t => services.AddScoped(t));
.Where(t => t.GetCustomAttribute<ServiceAttribute>() != null);

foreach (var t in serviceTypes)
{
services.AddSingleton(t);
}
}
}

0 comments on commit 6248f72

Please sign in to comment.