Combining dependency injection with localy defined parameters

Jun 25, 2010 at 11:48 AM
Edited Jun 25, 2010 at 11:50 AM

Hi!
I'm using design time configuration (App.Config) to configure my container (Unity 2.0). I'm looking for a solution to the following problem.
I have a class which has a constructor like the following:

public class MyClass : IMyClass
{
      public MyClass(IDependencyClass1 arg1, IDependencyClass2 arg2, string parameter1, string parameter2) { .... }
}

First two arguments are configured to be injected by unity. However the other two parameters are not, since their values are calculated/defined in runtime, just before the instantiation of MyClass. Also, they are not always the same, so I don't want to register them using runtime configuration.
Possible solutions?

One solution that occured to me up is to remove them from the constructor to another method called Configure. So my class would be something like the following:

public class MyClass : IMyClass
{
      public MyClass(IDependencyClass1 arg1, IDependencyClass2 arg2) { .... }
      public void Configure(string parameter1, string parameter2) { .... }
}

And I could use it like this:
var myInstance = container.Resolve<IMyClass>();
myInstance.Configure("value1", "value2");

What do you think?