Dotnet core Dependency Injection of Parameters

Viewed 8322

Suppose that I have the class

public class Entity : IEntity {
    public Entity(IDependency dep, string url)
    {
        //...
    }
}

public class Dependency : IDependency {
    //...
}

Now when I want to use dependency injection I can do something like:

IServiceCollection serviceCollection = new ServiceCollection();
serviceCollection.AddScoped<IDependency, Dependency>();
serviceCollection.AddScoped<IEntity, Entity>(); // how to inject the url

The problem, as you can see, is that I don't know how to inject a value of url (e.g. "https://google.com/"). I know structure map provides that with naming the parameters and their values.

Is there a way to inject a string into the constructor of Entity while using DI for the dependencies?

2 Answers
Related