Interface NET-如何在运行时选择接口的实现?
在Spring.NET IoC的所有示例中,我看到了如下内容:Interface NET-如何在运行时选择接口的实现?,interface,runtime,spring.net,Interface,Runtime,Spring.net,在Spring.NET IoC的所有示例中,我看到了如下内容: interface IClass; class ClassA : IClass; class ClassB : IClass, IClass c = [get me all implementations of IClass, and choose the one with GetType().FullName == myVariableContainingFullTypeNameOfObje
interface IClass;
class ClassA : IClass;
class ClassB : IClass,
IClass c = [get me all implementations of IClass, and choose the one with
GetType().FullName == myVariableContainingFullTypeNameOfObjectIWant]
然后在config.xml文件中,类似于:
[object id="IClass" type="ClassB, Spring.Net.Test" /]
但我确实需要在配置文件中执行类似的操作,如果接口:
[object id="IClass" type="ClassA, Blah" /]
[object id="IClass" type="ClassB, Blah" /]
然后在\u运行时
中,我从它们中进行选择。大概是这样的:
interface IClass;
class ClassA : IClass;
class ClassB : IClass,
IClass c = [get me all implementations of IClass, and choose the one with
GetType().FullName == myVariableContainingFullTypeNameOfObjectIWant]
我怎么能做这样的事
非常感谢 也许你可以试试这个: [object id=“Blah.ClassA”type=“ClassA,Blah”/ [objectid=“Blah.ClassB”type=“ClassB,Blah”/
IClass=(IClass)ApplicationContext.GetObject(myVariableContainingFullTypeNameOfObjectIWant) 也许你可以试试这个: [object id=“Blah.ClassA”type=“ClassA,Blah”/ [objectid=“Blah.ClassB”type=“ClassB,Blah”/
IClass=(IClass)ApplicationContext.GetObject(myVariableContainingFullTypeNameOfObjectIWant) 我以前也做过类似的事情,采取了与法比亚诺建议的方法非常相似的方法 示例配置: 下面是一些使用WebApplicationContext的通用示例代码:
IApplicationContext context = new XmlApplicationContext(locations);
IClass c = (IClass)context.GetObject(declarationId);
有几件事需要注意:
安德鲁我以前也做过类似的事情,采取了与法比亚诺建议的方法非常相似的方法 示例配置: 下面是一些使用WebApplicationContext的通用示例代码:
IApplicationContext context = new XmlApplicationContext(locations);
IClass c = (IClass)context.GetObject(declarationId);
有几件事需要注意: