Castle 带参数构造函数三种注入方式70%

注入带参构造函数三种种参数注入方法:

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);

Castle 带参数构造函数三种注入方式70%_第1张图片

container.Register(Component.For().Named("txtLog").ImplementedBy(typeof(TextFormatter)));            var log = container.Resolve("txtLog");

你可能感兴趣的:(Castle 带参数构造函数三种注入方式70%)