Tod,
Personally I find if you're injecting primative values into a constructor,
the class is possibly not a good candidate for IoC.
If it is a constant primative value (such as a configuration value) you can
add a binding parameter to add it on construction.
kernel.Bind<IMyService>().To<MyConcreteImplemention>().WithConstructorArgument("constructorArgumentName",
constantValue);
If the primative value changes during the lifetime of the application,
you're probably better off using the factory/provider pattern to create
you're objects and bind only the factory to the kernel, and use the factory
to create new instances of your class. e.g.
In Initialization / Module,
kernel.Bind<IMyObjectFactory>.To<MyObjectFactory>()
In a class that uses MyObject,
public class MyClassThatUsesObjects
{
private readonly IMyObjectFactory objFactory;
public MyClassThatUsesObjects(IMyObjectFactory objFactory)
{
this.objFactory = objFactory;
}
public void MethodThatUsesMyObject()
{
IMyObject obj = this.objFactory.CreateNew(param1, param2, param3,
etc..)
obj.CalculateSomethingImportant()
}
}
If it changes infrequently, you may just be better off using an
Initialize method or making the value a property and settings the value
after resolving the service.
IMyObject obj = kernel.Get<IMyService>();
obj.Initialize(5);
ovj.CalculateSomethingImportant() // Throw a NotInitializedException
if Initialize() hasn't been run first.
IMyObject obj = kernel.Get<IMyService>();
obj.RequiredProperty = 5;
obj.CalculateSomethingImportant() // Throw a
NotInitializatedException if RequiredProperty hasn't been set.
Regards,
Ben