I'm creating a service that requires some config parameters and a logger. Here is the constructor for my service:
public StorageProvider(string directory, ILogger<StorageProvider> logger)
I just added the logger. I used to initalize it like this in my startup.cs:
services.AddSingleton<IStorageProvider>(
new StorageProvider(Configuration["TempStorage.Path"]));
The directory parameter comes from the config file, and the logger gets DI'ed. How do I setup my IStorageProvider?
ILogger? Is that also a singleton? If so, pass that same instance to theILoggerregistration to theStorageProviderconstruction.IOptions<StorageProviderOptions>to inject the directory path.ILogger<StorageProvider>does not need an actual instance ofStorageProvider, if that's what you're thinking. The type param is for distinguishing log entries, it doesn't actually do anything with it.