Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configuration doesn't work with Dependency Injection

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

Jetski5822commented, Nov 10, 2017

You should never need to register the dependencies like this, you can just use the convenience method like below.


@juliavi are you using Autofac?

irinamiricicommented, May 3, 2023

I have the same issue: .AddMainChimpClient() cannot be found even when I add using 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:

    <PropertyGroup Condition="'$(TargetFramework)' == 'netstandard1.3' Or '$(TargetFramework)' == 'netstandard1.4' Or '$(TargetFramework)' == 'netstandard1.5' Or '$(TargetFramework)' == 'netstandard1.7' Or '$(TargetFramework)' == 'netstandard1.8' Or '$(TargetFramework)' == 'netstandard1.9' Or '$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'netcoreapp1.0' Or '$(TargetFramework)' == 'netcoreapp1.1' Or '$(TargetFramework)' == 'netcoreapp2.0' Or '$(TargetFramework)' == 'netcoreapp2.1' Or '$(TargetFramework)' == 'netcoreapp2.2'">

The parameterless constructor is not available for DI.

How should we register IMailChimpManager in a DI container? Thank you.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found