I have a .Net6 Console application.
I have a Startup.cs
public class Startup
{
public IConfiguration Configuration { get; private set; }
public Startup(IConfiguration configuration)
{
this.Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
services.Configure<Files>(Configuration.GetSection("Files"));
services.AddLogging(configure => configure.AddSerilog());
services.AddScoped<IHttpService, HttpService>();
}
}
then I have a Program.cs
class Program{
static void Main(string[] args)
{
...
var builder = new ConfigurationBuilder().AddJsonFile($"appsettings.json", true, true);
var config = builder.Build();
...
// Here is what I'm trying to do...
var svc = ActivatorUtilities.CreateInstance<IHttpService>();
}
}
but I'm not sure how to solve for ServiceProvider
then I see this guy who wired up his Program.cs
file w/o a Startup.cs
and he was able to get his service from the ActivatorUtilities.CreateInstance<T>(...)
so I'm wondering if I should too throw away the Startup.cs or is there a better way (I hope there is)