Configuration doesn't work with Dependency Injection
See original GitHub issueI’ve registered IMailChimpManager in the Startup class (MVC Core) And tried to configure the Api key like someone suggested on another issue:
services.AddScoped<IMailChimpManager, MailChimpManager>();
serviceProvider.GetService<IMailChimpManager>().Configure(x => x.ApiKey = "MyKey");
Then tried to add a member:
var member = new Member { EmailAddress = "email", StatusIfNew = Status.Subscribed };
await _mailChimpManager.Members.AddOrUpdateAsync(listId, member);
But I’m stil getting this error ‘Invalid URI: The hostname could not be parsed.’ This means that I didn’t configure the api-key correctly. Any ideas how to do it with dependency injection in MVC Core?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Dependency Injection not working for IConfiguration C#. ...
I use this one in ASP.Net Core and works it for me: public class Startup { public Startup(IHostingEnvironment env , IConfiguration ...
Read more >Dependency injection in ASP.NET Core
Dependency injection addresses these problems through: The use of an interface or base class to abstract the dependency implementation.
Read more >Configuration Settings Are A Dependency That Should Be ...
Dependency Injection does not just apply to obvious dependencies such as repositories and logging components. It is very important to inject ALL dependencies ......
Read more >Accessing config file and dependency injection not working ...
I'm trying to access the configuration file in my main class but it doesn't want to work with me, to be exact, it's...
Read more >How do you manage config with dependency injection?
Create a configuration class (to be picky: an interface + an implementation) which purpose is to provide the information about the environment.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You should never need to register the dependencies like this, you can just use the convenience method like below.
@juliavi are you using Autofac?
I have the same issue:
.AddMainChimpClient()
cannot be found even when I addusing MailChimp.Net;
I think the problem is that the extension is available under this directive:And .NET 7 doesn’t appear to be considered NET_CORE when the constant is defined:
The parameterless constructor is not available for DI.
How should we register
IMailChimpManager
in a DI container? Thank you.