Access interface methods without referring the class

后端 未结 5 1121
礼貌的吻别
礼貌的吻别 2021-01-22 20:26

Say I have an Interface like this in a project called \"Interface\":

public interface TestInterface
{
    string Operation();
}

and class which

5条回答
  •  日久生厌
    2021-01-22 20:56

    you can achieve the behavior you have described via using IOC. Unity is a dependency injection container which allows to create instances without manually creating instances.

    For instance, if you were to register your class and interface to unity, you would directly use the interface;

    TestInterface i = Container.Resolve();
    

提交回复
热议问题