日期:2014-05-17  浏览次数:20344 次

unity中,有谁用过构造函数注入.
如下面的程序:
public class test
{
  test(string aa)
  {
  console.write(aa);
  }
  
  test(int b)
  {
  console.write(b.tostring());
  }
}

我想在另一个类中调用test(string aa)这个构造器.

IUnityContainer container = new UnityContainer();
container.RegisterInstance("testName", "hello world");

container.RegisterType<test>(new IndjectContructor(new ResolveParmeter<string>("testName")));


//调用
test t = container.Resolve<test>();
我这里想调用test(string aa)这个构造函数,输出结果hello world.

但上面的程序无法实现,请教高手.




------解决方案--------------------
up
------解决方案--------------------
http://www.cnblogs.com/overred/articles/1090708.html

4.在实现注册映射时构造函数public Log(ILogFormatter format)参数不能为string,int等值类型,需要为接口或者类

------解决方案--------------------
container.RegisterInstance("testName", "hello world");
container.RegisterType<test>(new InjectionConstructor(new ResolvedParameter<string>("testName"))); 
是调用test(string aa)这个构造函数呀,晕..
------解决方案--------------------
探讨
http://www.cnblogs.com/overred/articles/1090708.html

4.在实现注册映射时构造函数public Log(ILogFormatter format)参数不能为string,int等值类型,需要为接口或者类