注入带参构造函数三种种参数注入方法:
1.dependson
Castle.Windsor.IWindsorContainer container = new WindsorContainer(); container.Register(Component.For().ImplementedBy(typeof(Test)).DependsOn(dependency: Dependency.OnValue("gg","1")));
ITest test = container.Resolve();
2.resolve parameter
IDictionary parameters = new Hashtable { { "gg", "dfgd"}}; // ITest test= container.Resolve(parameters);
3.
Castle.Windsor.IWindsorContainer container = new WindsorContainer(new XmlInterpreter());
container.Register( Component.For() .ImplementedBy() ); ITest test = container.Resolve("ITest");
test.hello(null);
container.Register(Component.For().Named("txtLog").ImplementedBy(typeof(TextFormatter))); var log = container.Resolve("txtLog");