How to bind IDictionary property with Ninject?

I assume this is a fixed list. The easiest way would be with a provider: public class MyProvider : IProvider { public object Create(IContext context) { return new Dictionary{ {"alpha", context.Kernel.Get()}, {"beta", context.Kernel.Get()} } } public Type Type { get { return typeof(IDictionary); } } } You can register the provider to your kernel like: kernel.Bind().ToProvider() and then the Inject for the property will use the provider to create the dictionary.

I assume this is a fixed list. The easiest way would be with a provider: public class MyProvider : IProvider { public object Create(IContext context) { return new Dictionary{ {"alpha", context.Kernel.Get()}, {"beta", context.Kernel.Get()} } } public Type Type { get { return typeof(IDictionary); } } } You can register the provider to your kernel like: kernel.Bind().ToProvider(); and then the Inject for the property will use the provider to create the dictionary.

Thanks, still learning Ninject and didn't know about providers yet. – Ronald Wildenberg Sep 19 at 6:16.

In case the key can somehow be retrieved/generated/calculated from IMyInterface e.g. From a Name property then there is an easy solution. Public class DictionaryProvider : Provider> { private IEmumerable instances; public DictionaryProvider(IEmumerable instances>) { this. Instances = instances; } protected override IDictionary CreateInstance(IContext context) { return this.instances.

ToDictionary(i => i. Name); } } Otherwise ryber's solution is probably the easiest way to go.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions