I am testing the latest build of StructureMap to find out about IoC containers, etc. As my first test, I have the following class:
public class Hospital { private Person Person { get; set; } private int Level { get; set; } public Hospital(Person employee, int level) { Person = employee; Level = level; } public void ShowId() { Console.WriteLine(this.Level); this.Person.Identify(); } }
Then I use StructureMap as follows:
static void Main() { ObjectFactory.Configure(x => { x.For<Person>().Use<Doctor>(); x.ForConcreteType<Hospital>().Configure.Ctor<int>().Equals(23); }); var h = ObjectFactory.GetInstance<Hospital>(); h.ShowId(); }
So, I pass the Doctor object as the first constructor parameter to the hospital, and I try to set the level parameter to 23. When I run the above code, I get:
Unhandled exception: StructureMap.StructureMapException: StructureMap exception code: 205 The requested instance property "Level" for InstanceKey "5f8c4b74-a398-43f7- 91d5-cfefcdf120cf" is missing
So it looks like I'm not setting the level parameter at all. Can someone point me in the right direction - how to set the level parameter in the constructor?
Greetings. Jac.
structuremap
Jason evans
source share