jjzjj

IInterface1

全部标签

c# - 使用单个接口(interface)注册多个实现

有没有一种方法可以在不使用模板接口(interface)的情况下使用[simple-injector]注册由多个具体类实现的单个接口(interface)?假设我们有2个类MyClass1和Myclass2并且这两个类都实现了IInterface1现在使用[simple-injector]我们无法做到这一点container.Register();container.Register();将现有界面转换为模板界面在现有代码库上是一项艰巨的工作。希望那里有一些更简单的东西。 最佳答案 您可以使用RegisterCollection方法

c# - 在 C# 中,如果我的对象支持该接口(interface),我如何检查 T 是否属于 IInterface 类型并强制转换为该类型?

在C#中,我有一个使用generics传入T的函数,我想运行一个检查以查看T是否是一个object实现了一个interface,如果是的话调用那个interface上的methods之一。我不想让T约束只属于那种类型。可以这样做吗?例如:publicclassMyModel:IModelwhereT:MyObjectBase{publicIQueryableGetRecords(){varentities=Repository.Query();if(typeof(IFilterable).IsAssignableFrom(typeof(T))){//Filtermeisamethodt

c# - 网络核心 : register implementation with multiple interfaces and lifestyle Singleton

考虑以下接口(interface)和类定义:publicinterfaceIInterface1{}publicinterfaceIInterface2{}publicclassMyClass:IInterface1,IInterface2{}有没有办法像这样用多个接口(interface)注册一个MyClass的实例:...services.AddSingleton();...并用像这样的不同接口(interface)解析MyClass的单个实例:IInterface1interface1=app.ApplicationServices.GetService();IInterface

c# - 网络核心 : register implementation with multiple interfaces and lifestyle Singleton

考虑以下接口(interface)和类定义:publicinterfaceIInterface1{}publicinterfaceIInterface2{}publicclassMyClass:IInterface1,IInterface2{}有没有办法像这样用多个接口(interface)注册一个MyClass的实例:...services.AddSingleton();...并用像这样的不同接口(interface)解析MyClass的单个实例:IInterface1interface1=app.ApplicationServices.GetService();IInterface

c# - 无法实现接口(interface)成员,因为它没有 List<IInterface> 的匹配返回类型

我有接口(interface)IChild和IParent.IParent有一个成员是List.我希望有实现IParent的类每个类都有一个实现IChild的成员:publicinterfaceIChild{}publicinterfaceIParent{Lista{get;set;}}publicclassChildA:IChild{}publicclassChildB:IChild{}publicclassParentA:IParent{publicLista{get;set;}}publicclassParentB:IParent{publicLista{get;set;}}但是