New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register and resolving classes with primitive parameters #605

Open
vkg-mca opened this Issue Aug 10, 2018 · 1 comment

Comments

2 participants
@vkg-mca

vkg-mca commented Aug 10, 2018

I am using Simple Injector version 4.3.0. and have a problem where I want to register a class with single constructor having three string parameters, but parameter values are not known until runtime. So my problem is

Step#1

private Container container = new Container();
container.RegisterSingleton<IEventHubConfiguration, EventHubConfiguration>();

Class has three parameters

Step#2

public class EventHubConfiguration : IEventHubConfiguration
{
    public EventHubConfiguration(string key, string value, string account)
    {
        //Some code here
    }
}

PROBBLEM=>

In Step#1, I cannot register the class as it is asking for all three parameters to be passed. I can NOT pass the parameter values because these are NOT known yet. I can pass hardcoded values during registration and update them back when get the actual values but not sure if this is right solution.

@dotnetjunkie dotnetjunkie changed the title from Resgistering and resolving classes with primitive parameters to Register and resolving classes with primitive parameters Aug 10, 2018

@dotnetjunkie

This comment has been minimized.

Collaborator

dotnetjunkie commented Aug 10, 2018

You'll find the source of your trouble and the solution in the article Dependency-injection Code Smell: Injecting runtime data into components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment