Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Inversion of control IoC会议注册和一个类上的多个接口_Inversion Of Control_Ioc Container - Fatal编程技术网

Inversion of control IoC会议注册和一个类上的多个接口

Inversion of control IoC会议注册和一个类上的多个接口,inversion-of-control,ioc-container,Inversion Of Control,Ioc Container,假设我们在一个类上有多个接口 Class1: IInterface1, Interface2 {} 在某些情况下,我们希望使用IInterface1/IInterface2将这些依赖项的实现注入到单独的类中 Class Foo1(IInterface1 interface1) {} Class Foo2(IInterface2 interface2) {} 我们将在容器中注册这两个接口 container.Register<IInterface1,Class1>(); cont

假设我们在一个类上有多个接口

Class1: IInterface1, Interface2 {}
在某些情况下,我们希望使用IInterface1/IInterface2将这些依赖项的实现注入到单独的类中

Class Foo1(IInterface1 interface1) {}

Class Foo2(IInterface2 interface2) {}
我们将在容器中注册这两个接口

container.Register<IInterface1,Class1>();
container.Register<IInterface2,Class1>();
container.Register();
container.Register();
目前我所做的是从类类型信息中读取接口,并将其上的接口注册到类中(使用反射)。不过这里没有惯例


这些场景通常是如何处理的。我们可以在这些场景中使用任何特定的命名约定,或者通过读取类类型信息来注册接口就足够了吗?

我认为将多个接口注册到一个类中没有固有的问题。你有什么问题吗?我更想知道的是,你会如何遵循这方面的惯例。从类中读取接口并对其进行注册真的是一种约定吗?与IClass1和Class1等类似的名称约定不同,定义一个在代码库中有意义的约定取决于您自己。我认为这个问题不应该有一个明确的答案。谢谢你的回答。我只是想检查一下,在这种情况下,是否遵循了任何惯例,因为这些情况通常会发生。所以现在我认为从类定义注册回接口就足够了