I am using Ninject with Windows Phone application.
My logic includes IBarViewModel interface which is:
public interface IBarViewModel
{
double Width { get; set; }
bool IsAchieved { get; set; }
CornerRadius Corner { get; set; }
}
Currently, there is only one implementatation of IBarViewModel – GenericBarViewModel.
All the IViewModel implementators will have to have these three main properties set at creation time.
I want to create an instances of these IBarViewModels at runtime from my code. How can I do it.
When I was programming against an implementation (the class was called simply Bar), I was just calling an object initializer like this:
_bars.Add(new Bar
{
Width = _totalWidth,
IsAchieved = false,
Corner = new CornerRadius(5, 5, 5, 5)
});
As per the answer to this question: Inject value into injected dependency I can pass a parameter to ninject module.
The only question remains: will I have to carry my ninject kernel deep into the logic to do such parametrized dependency resolution?
I don’t think you should be using IoC at all for this. It doesn’t make any sense whatsoever.
Why not simply let the
GenericBarViewModelset the default values for the 3 properties, make it abstract, and let any other “Bar” ViewModel implementations inherit from theGenericBarViewModel?What exactly are you trying to do?