注:如类有共有的构造函数而且没有使用Dependency特性,可以在不需要注册映射关系的前提下,使用容器生成实例

1、获取默认映射

IMyService result = myContainer.Resolve<IMyService>();

2、获取命名映射

IMyService result = myContainer.Resolve<IMyService>("Data");

3、获取注册的所有对象

IEnumerable<IMyObject> objects = myContainer.ResolveAll<IMyObject>();

如果没有命名映射将返回Null

  foreach (IMyObject foundObject in objects) {

// convert the object reference to the "real" type

MyRealObject theObject = foundObject as MyRealObject;

if (null != theObject)

// work with the object

{

         Console.WriteLine(theObject.SomeProperty);

}

}

相关文章:

  • 2021-09-06
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
  • 2021-08-18
  • 2021-04-24
  • 2021-10-11
  • 2021-04-01
猜你喜欢
  • 2021-05-26
  • 2021-06-24
  • 2021-10-10
  • 2021-10-09
  • 2021-12-05
  • 2021-10-27
  • 2022-02-06
相关资源
相似解决方案