Hello @JustinCanton,
I was updating the version in order to add the Radar Geocoding you added support for.
I saw that the dependency injection has changed, and I can't find the way to make it work. In a second post, I will also show you some issues with the tests I was trying to do.
But let's see the first issue:
The problem is that the DI moved from services.AddHereServices to var builder = services.AddHereGeocoding(); and this won't work with my actual code.
Do you know any solution?
This Is how I was doing it before:
Program.cs
public class Program
{
public static void Main(string[] args)
{
Logger logger = LogManager.Setup().GetCurrentClassLogger();
try
{
logger.Debug("Starting the website");
CreateHostBuilder(args).Build().Run();
}
catch (Exception exception)
{
//NLog: catch setup errors
logger.Error(exception, "Stopped the website of an exception");
throw;
}
finally
{
// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
LogManager.Shutdown();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostContext, configApp) =>
{
configApp.AddJsonFile("appSettings.json", optional: false);
// OTHER CONFIGURATIONS
configApp.AddJsonFile($"appSettings.{hostContext.HostingEnvironment.EnvironmentName}.json", optional: false);
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
}).ConfigureLogging(logging =>
{
logging.ClearProviders();
})
.UseNLog();
}
Startup.cs
public class Startup
{
private IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
// OTHER CONFIGURATIONS
}
public void ConfigureServices(IServiceCollection services)
{
// DEPENDENCY INJECTION
IOC.InjectDependencies(Configuration, services);
// OTHER CONFIGURATIONS
}
}
IOC.cs
public class IOC
{
public static void InjectDependencies(IConfiguration configuration, IServiceCollection services)
{
// APPLICATION CONFIGURATION
//services.Configure<...
// SERVICES & REPOSITORIES
//services.AddTransient<...
// REPOSITORIES
//services.AddTransient<...
//HELPERS
//services.AddSingleton<...
// GEOCODING HELPERS
services.AddHereServices(options => options.UseKey(configuration.GetValue<string>("ApplicationConfiguration:GeoCoding:HereGeocodingApiKey")));
services.AddSingleton<IGeocodingHelpers, HereGeocodingHelpers>();
}
}
Now I can't find a way to adapt
services.AddHereServices(options => options.UseKey(configuration.GetValue<string>("ApplicationConfiguration:GeoCoding:HereGeocodingApiKey")));
With
services.AddHereGeocoding();
This also returns to a conversation we had some time ago, about configuring the API keys / secrets at runtime.
Is there a way of doing this??
Many thanks