I have a base Document DB repository in the infrastructure layer of my solution. I based this repository on this GitHub project, which is a static class that is utilized by my other domain model repositories.
In my API layer I have config.json files that are environment specific. I would like to use dependency injection to be able to use my configuration class that reads the DocumentDB settings defined in the API layer in the deeper Infrastructure layer. This StackOverflow answer details how to use DI with an API controller, however I can't figure out how to use DI in this case, as a static class, I don't have a constructor. Is it possible to use DI with my static repository? If not, how should I read config settings into the infrastructure layer?
My ConfigurationOptions class (in Infrastructure layer):
public class ConfigurationOptions
{
public string EndpointUri { get; set; }
}
My DocumentDbRepository class (in Infrastructure layer):
public static class DocumentDbRepository<T>
{
// I want to read these strings from my config.json files
private static string EndpointUri { get; } = ConfigurationOptions.EndpointUri;
//...
private static Document GetDocument(string id)
{
return Client.CreateDocumentQuery(Collection.DocumentsLink)
.Where(d => d.Id == id)
.AsEnumerable()
.FirstOrDefault();
}
}
Part of my Startup class (in my API layer)
public class Startup
{
public IConfiguration Configuration { get; set; }
public void ConfigureServices(IServiceCollection services)
{
services.Configure<ConfigurationOptions>(options =>
options.EndpointUri = Configuration.Get("EndpointUri"));
// ...
}
// ...
}