本文介绍了使用接口解析类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


请让我知道使用UNITY的接口使用接口解析类的概念...
一个简单的例子....

Hi,
please let me know the concept of Resolving class using interface using UNITY ...
with a simple example....

推荐答案

interface IThing { int DoStuff(); }
class Thing: IThing { public int DoStuff(){ return 42; } }

void UnityTest(){
 // Here''s how you register
 unityContainer.RegisterType<IThing, Thing>();

 // ... and here''s how you resolve
 IThing thing = unityContainer.Resolve<IThing>();
 
 int answer = thing.DoStuff(); // will be 42
}



我确定Google可以找到您.在此询问之前,请先花点力气.



I''m sure Google could have found you that. Please put a bit of effort in before asking on here.


这篇关于使用接口解析类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 16:15