开发者

Interface with method GetInstance<T>() in .Net?

I am not sure if there is any interface already exist in .Net like this:

public interface IController {
      T GetInstance<T>(string name) where T: class;
}

Basically, this in开发者_C百科terface contains a method to get instance of T by name/key. IControler is an arbitrator name I use here. It may be something like IFactory, ICreator, or something I don't know. The method name may not exactly like this(GetInstance). I think this may be a generic method which can be used to get/query an instance from a container, parent or controller.

If there is one, I would not need to create one(just adding a reference); otherwise, I'll define one.


this sounds exactly like an IoC container. You might want to look at the common service locator


This problem has generally been solved by container-managed repositories, which are at the heart of Dependency Injection frameworks like Unity, StructureMap and NInject.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜