Search code examples
ninject

How do I inject a property of a primitive type using Ninject?


How do I inject the name "Tommy" into the Name property of Bar when instantiating / activating a Foo object?

class Foo
    {
        public Bar Bar { get; set; }

        public Foo(Bar b) { Bar = b; }
    }

    class Bar
    {
        [Inject]
        public string Name { get; set; }
    }

Solution

  • kernel.Bind<Bar>().ToSelf().WithPropertyValue("Name", "Tommy");